|
안녕하세요.
한 2일 동안 계속 컴퓨터 앞에 앉아서 레포트 프로그램 짜다 보니...
머리가 바보가 된거 같습니다.
질문 하나 드리겠습니다.
아래 소스 코드를 For문으로 돌리면 아주 작아 질 거 같은데...
그게 생각이 안나네요.
흑흑흑...
도와주세요!
(아래의 요점은 survey와 surgery를 비교해서 같은 문자만 출력 하는것입니다)
(surey 이렇게요...)
#include <stdio.h>
#include <string.h>
void main(void)
{
char word_a_1[] = "s";
char word_a_2[] = "u";
char word_a_3[] = "r";
char word_a_4[] = "v";
char word_a_5[] = "e";
char word_a_6[] = "y";
char word_b_1[] = "s";
char word_b_2[] = "u";
char word_b_3[] = "r";
char word_b_4[] = "g";
char word_b_5[] = "e";
char word_b_6[] = "r";
char word_b_7[] = "y";
//첫번째 문자열 비교
if (!stricmp(word_a_1, word_b_1))
{
printf("%s", word_a_1);
}
else if (!stricmp(word_a_1, word_b_2))
{
printf("%s", word_a_1);
}
else if (!stricmp(word_a_1, word_b_3))
{
printf("%s", word_a_1);
}
else if (!stricmp(word_a_1, word_b_4))
{
printf("%s", word_a_1);
}
else if (!stricmp(word_a_1, word_b_5))
{
printf("%s", word_a_1);
}
else if (!stricmp(word_a_1, word_b_6))
{
printf("%s", word_a_1);
}
else if (!stricmp(word_a_1, word_b_7))
{
printf("%s", word_a_1);
}
// 두번재 문자열 비교
if (!stricmp(word_a_2, word_b_2))
{
printf("%s", word_a_2);
}
else if (!stricmp(word_a_2, word_b_3))
{
printf("%s", word_a_2);
}
else if (!stricmp(word_a_2, word_b_4))
{
printf("%s", word_a_2);
}
else if (!stricmp(word_a_2, word_b_5))
{
printf("%s", word_a_2);
}
else if (!stricmp(word_a_2, word_b_6))
{
printf("%s", word_a_2);
}
else if (!stricmp(word_a_2, word_b_7))
{
printf("%s", word_a_2);
}
//세번째 문자열 비교
if (!stricmp(word_a_3, word_b_3))
{
printf("%s", word_a_3);
}
else if (!stricmp(word_a_3, word_b_4))
{
printf("%s", word_a_3);
}
else if (!stricmp(word_a_3, word_b_5))
{
printf("%s", word_a_3);
}
else if (!stricmp(word_a_3, word_b_6))
{
printf("%s", word_a_3);
}
else if (!stricmp(word_a_3, word_b_7))
{
printf("%s", word_a_3);
}
//네번째 문자열 비교
if (!stricmp(word_a_4, word_b_4))
{
printf("%s", word_a_4);
}
else if (!stricmp(word_a_4, word_b_5))
{
printf("%s", word_a_4);
}
else if (!stricmp(word_a_4, word_b_6))
{
printf("%s", word_a_4);
}
else if (!stricmp(word_a_4, word_b_7))
{
printf("%s", word_a_4);
}
//다섯번째 문자열 비교
if (!stricmp(word_a_5, word_b_5))
{
printf("%s", word_a_5);
}
else if (!stricmp(word_a_5, word_b_6))
{
printf("%s", word_a_5);
}
else if (!stricmp(word_a_5, word_b_7))
{
printf("%s", word_a_5);
}
//여섯번째 문자열 비교
if (!stricmp(word_a_6, word_b_6))
{
printf("%s\n", word_a_6);
}
else if (!stricmp(word_a_6, word_b_7))
{
printf("%s\n", word_a_6);
}
}
|