实现strcmp

#include<stdio.h>
int mystrcmp(const char* str, const char* dst)
{
    int ret = 0;
    while (!(ret = *(unsigned char*)str - *(unsigned char*)dst) && *dst)
    {
        ++str,
        ++dst;
    }
    if (ret < 0)
    {
        ret = -1;
    }
    else if (ret > 0)
    {
        ret = 1;
    }
    return ret;
}
int main()
{
    char* str = "abcdefgh";
    char* dst = "abddef";
    int ret = mystrcmp(str, dst);
    printf("%d\n", ret);
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lly17792230965/article/details/80097490