stricmp ()- 不區分大小寫的比較字串

格式

#include <string.h>
int stricmp(const char *string1, const char *string2);
附註: stricmp() 函數適用於 C++ 程式。 只有在程式定義 __cplusplus__strings__ 巨集時,它才適用於 C。

語言層次

分機

安全執行緒

區分語言環境

此函數的行為可能受現行語言環境的 LC_CTYPE 種類影響。 如需相關資訊,請參閱 瞭解 CCSID 及語言環境

說明

stricmp() 函數會比較 string1string2 ,而不區分大小寫。 在比較之前,兩個引數 string1string2 中的所有英文字母都會轉換成小寫。

函數對空值結束字串進行操作。 預期函數的字串引數包含空值字元 (\0) ,標示字串結尾。

回覆值

stricmp() 函數會傳回一個值,指出兩個字串之間的關係,如下所示:

表 1. stricmp() 的回覆值
Value 意義
小於 0 string1 小於 string2
0 string1 相當於 string2
大於 0 string1 大於 string2

範例

此範例使用 stricmp() 來比較兩個字串。
#include <stdio.h>
#include <string.h>
int main(void)
{
   /* Compare two strings as lowercase                              */
   if (0 == stricmp("hello", "HELLO"))
      printf("The strings are equivalent.\n");
   else
      printf("The strings are not equivalent.\n");
   return 0;
}
輸出應該為:
      The strings are equivalent.

相關資訊