Compare two strings without the strcmp function

#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;
}

Guess you like

Origin blog.csdn.net/zhangxue1232/article/details/104836412