Case Insensitive String comp in C

前端 未结 11 1176
天涯浪人
天涯浪人 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:13

    As others have stated, there is no portable function that works on all systems. You can partially circumvent this with simple ifdef:

    #include 
    
    #ifdef _WIN32
    #include 
    #define strcasecmp _stricmp
    #else // assuming POSIX or BSD compliant system
    #include 
    #endif
    
    int main() {
        printf("%d", strcasecmp("teSt", "TEst"));
    }
    

提交回复
热议问题