代码
//比较字符串
#include<stdio.h>
#include<string.h>
int myCompare(const char* s1, const char* s2);
int main()
{
char s1[10];
char s2[10];
printf("input s1:");
scanf("%s",&s1);
printf("input s2:");
scanf("%s",&s2);
printf("%d",myCompare(s1,s2));
return 0;
}
int myCompare(const char* s1, const char* s2)
{
while(*s1==*s2 && *s1 != '\0')
{
s1++;
s2++;
}
return *s1 - *s2;
}
网友评论