1. 程式人生 > >不區分大小寫的串比較---Windows下的stricmp和Linux下的strcasecmp

不區分大小寫的串比較---Windows下的stricmp和Linux下的strcasecmp

 不區分大小寫的串比較, 在實戰中的應用還是很廣泛的, 有時候可以增強程式的容錯性, 下面我們來分別看看Windows下的stricmp和Linux下的strcasecmp

     

Windows下的stricmp:

#include <stdio.h>
#include <string.h>
 
int main()
{
    if(0 == stricmp("abc", "ABc"))
    {
        printf("yes1\n"); // yes
    }
 
    if(0 == stricmp("ABCx", "ABC"))
    {
        printf("yes2\n"); // 不執行
    }
 
    return 0;
}

Linux下的strcasecmp:

#include <stdio.h>
#include <string.h>
 
int main()
{
    if(0 == strcasecmp("abc", "ABc"))
    {
        printf("yes1\n"); // yes
    }
 
    if(0 == strcasecmp("ABCx", "ABC"))
    {
        printf("yes2\n"); // 不執行
    }
 
    return 0;
}