c 语言实现strcasecmp


#define __tolower(c)    ((('A' <= (c))&&((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c))


int strcasecmp(const char *s1, const char *s2)
{
    const unsigned char *p1 = (const unsigned char *) s1;
    const unsigned char *p2 = (const unsigned char *) s2;
    int result = 0;

    if (p1 == p2)
    {
        return 0;
    }

    while ((result = __tolower(*p1) - __tolower(*p2)) == 0)
    {
        if (*p1++ == '\0')
        {
            break;
        }
    p2++;
    }

    return result;
}


你可能感兴趣的:(c,语言)