欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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