Case Insensitive String comp in C

前端 未结 11 1179
天涯浪人
天涯浪人 2020-11-27 03:45

I have two postcodes char* that I want to compare, ignoring case. Is there a function to do this?

Or do I have to loop through each use the tolower func

11条回答
  •  庸人自扰
    2020-11-27 04:20

    static int ignoreCaseComp (const char *str1, const char *str2, int length)
    {
        int k;
        for (k = 0; k < length; k++)
        {
    
            if ((str1[k] | 32) != (str2[k] | 32))
                break;
        }
    
        if (k != length)
            return 1;
        return 0;
    }
    

    Reference

提交回复
热议问题