c 언어 질문입니다.
Isolation
#include stdio.h
#define SKY sky
int My_strcmp(const char*string1,const char*string2);
void main(void)
{
char string[100];
int ret;
printf(영어단어를 입력후 Enter키 를 치세요 \n);
printf(sky를 입력하면 프로그램이 종료됩니다.\n);
do{
gets(string);
ret=My_strcmp(string,SKY);
if(ret==0)
{
printf(%s == %s, ret =%d \n,string,SKY,ret);
break;
}
else if (ret0) printf(%s%s,ret=%d \n,string,SKY,ret);
else printf(%s %s,ret = %d \n,string,SKY,ret);
}while(1);
}
int My_strcmp(const char*string1,const char*string2)
{
if(*string1 ==(int)NULL && *string2 ==(int)NULL) return 0;
while(*string1 != (int)NULL)
{
if(*string2 == (int)NULL) return 1;
if(*string1 == *string2)
{
string1++;
string2++;
continue;
}
if(*string1 *string2) return -1;
else return 1;
}
if(*string2 != (int)NULL) return -1;
return 0;
}
----------------------------------------------------------------
위 프로그램에서 빨간색 글씨로 된 부분이 이해가 잘안돼서 그러는데..
한줄 한줄 자세히 설명좀 부탁 드리겠습니다.
모두 좋은 하루 보내세요
-
팬지
넘 복잡하게 짠 소스군요.....
int My_strcmp(const char*string1,const char*string2)
{
while( *string1 && *string2 && *string1==*string2 )
{
++string1, ++string2;
}
return *string1 - *string2;
}