strcmp函数实现(c语言)
程序员文章站
2022-07-07 11:38:52
...
strcmp函数实现(c语言)
second60 20180601
#include <stdio.h>
int strcmp_new(const char* src, const char* dst)
{
int ret = 0;
while( !(ret = *(unsigned char*)src - *(unsigned char*)dst) && *dst)
{
src ++;
dst ++;
}
if( ret < 0) ret = -1;
else if(ret > 0) ret = 1;
return ret;
}
int main()
{
char str[10] = "1234";
char str1[10] = "1234";
int ret1 = strcmp_new(str,str1);
printf("ret=%d\n", ret1);
getchar();
return 0;
}
下一篇: 函数类型,函数指针类型,函数指针