不区分大小写字符串比较函数

时间:2022-02-23 01:00:07

int strnicmp(char *s1, char __code *s2,  int len)
{
    unsigned char c1, c2;
    if(!len)
        return 0;
    do{
        c1 = *s1++;
        c2 = *s2++;
        if (!c1 || !c2)
            break;
        if (c1 == c2)
            continue;
        c1 = tolower(c1);
        c2 = tolower(c2);
        if (c1 != c2)
            break;
    }while(--len);
    return (int)c1 - (int)c2;
}