//自写字符串比较函数
#include <stdio.h>
int strcmp(char ch1[], char ch2[]);
int main()
{
char ch1[80], ch2[80];
int result;
printf("请输入第一个字符串:");
gets(ch1);
printf("请输入第二个字符串:");
gets(ch2);
result = strcmp(ch1, ch2);
if(result == 0) printf("两个字符串相等");
else if(result > 0) printf("第一个字符串大于第二个字符串");
else if(result < 0) printf("第一个字符串小于第二个字符串");
return 0;
}
int strcmp(char ch1[],char ch2[])
{
int ret;
char *str1 = ch1, *str2 = ch2;
while(1){
ret = *str1 - *str2;
if(ret != 0) break;
//printf("%d", ret);
if(*str1 == '\n' && *str2 == '\n'){
ret = 0;
break;
}
if(*str1 == '\n' || *str2 == '\n'){
ret = *str1 - *str2;
break;
}
str1++, str2++;
}
//printf("%d", ret);
return ret;
}