strcmpi,stricmp函數

來源:互聯網
上載者:User

函數原型:extern int strcmpi(char *str1,char * str2)

                   或者 extern int stricmp(char *str1,char * str2)

參數說明:str1為第一個要比較的字串,str2為第二個要比較的字串。
       
所在庫名:#include <string.h>
 
函數功能:比較字串str1和str2,但是不區分字母的大小寫(這點就是與strcmp的區別)。

返回說明:返回整數值:當str1<str2時,傳回值<0; 當str1=str2時,傳回值=0; 當str1>str2時,傳回值>0。

其它說明:暫時無。

執行個體:

第一種情形:

#include <string.h>
#include <stdio.h>
int main()
...{
    char *str1="SKY2098!";
    char *str2="sky2098,I like writing!";   //str1與str2的大小寫不一樣,而且長度不同

    int inttemp;

    inttemp=strcmpi(str1,str2);   //將字串比較的傳回值儲存在int型變數inttemp中,用strcmpi函數
    if(inttemp<0)
    ...{
        printf("lexicographic(str1) < lexicographic(str2) ");
    }
    else if(inttemp>0)
        ...{
            printf("lexicographic(str1) > lexicographic(str2) ");
        }
        else
        ...{
            printf("lexicographic(str1) == lexicographic(str2) ");
        }
    return 0;
}

在VC++ 6.0 編譯運行:

顯然當str1與str2比較後,由於str1是str2的子串,故而str2的字典序比str1要大,傳回值<0。

第二種情形:

#include <string.h>
#include <stdio.h>
int main()
...{
    char *str1="SKY2098,I liKE wrITing!";
    char *str2="sky2098,I like writing!";   //str1與str2的大小寫不一樣,但是代表的含義一樣,也就是str1的字典序與str2相同,不區分大小寫
    int inttemp;

    inttemp=strcmpi(str1,str2);   //將字串比較的傳回值儲存在int型變數inttemp中,用strcmpi函數
    if(inttemp<0)
    ...{
        printf("lexicographic(str1) < lexicographic(str2) ");
    }
    else if(inttemp>0)
        ...{
            printf("lexicographic(str1) > lexicographic(str2) ");
        }
        else
        ...{
            printf("lexicographic(str1) == lexicographic(str2) ");
        }
    return 0;
}

在VC++ 6.0 編譯運行:

 strcmpi與stricmp具有相同的功能。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.