比较两个字符串,不用strcmp函数

#include<stdio.h>
int main()
{
    int i,n;
    char s1[100], s2[100];
    gets(s1);
    gets(s2);
    i=0;
    while(s1[i]==s2[i]&&s1[i]!='\0') i++;
    if(s1[i]=='\0'&&s2[i]=='\0')
        n=0;
    else
        n=s1[i]-s2[i];
    printf("%d\n",n);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/zhangxue1232/article/details/104836412