#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int my_strcmp(const char* s1, const char* s2)
{
while (*s1 == *s2)
{
if (*s1 == '\0')
{
return 0;
}
s1++;
s2++;
}
return *s1 - *s2;
}
int main()
{
int ret = my_strcmp("abcdef", "abc");
if (ret > 0)
{
printf("大于\n");
}
else if (ret == 0)
{
printf("等于\n");
}
else
{
printf("小于\n");
}
}
【C语言】每日一代码:strcmp模拟实现
最新推荐文章于 2024-06-20 00:37:45 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)