#include<stdio.h>
#include<assert.h>
#include<string.h>
int my_strcmp(const char* s1,const char* s2)
{
//一个一个字符的ASCII码值比较,s1大返回大于0的数,s1小返回小于0的数,相等返回0
while (*s1 == *s2)
{
if (*s1 == '\0')
{
return 0;
}
s1++;
s2++;
}
/*if (*s1 > *s2)
{
return 1;
}
if (*s1 < *s2)
{
return -1;
}*/
return *s1 - *s2;
}
int main()
{
//模拟实现strcmp(字符串比较)的功能
char arr1[] = "ab";
char arr2[] = "abaw";
//printf("%d", strcmp(arr1, arr2));
int ret=my_strcmp(arr1, arr2);
printf("%d", ret);
return 0;
}