C/C++ 中的 strcoll()


strcoll() 函式用於使用特定於區域設定的排序序列比較兩個字串。

它返回−

  • 當兩個字串相同時的零值,
  • 當第一個字串大於另一個字串時的大於零的值
  • 當第一個字串小於另一個字串時的小於零的值。

以下是 C 語言中 strcoll() 的語法,

int strcoll(const char *first_string, const char *second_string);

以下是 C 語言中 strcoll() 的一個示例,

示例

 即時演示

#include <stdio.h>
#include <string.h>
int main () {
   const char s1[] = "Helloworld";
   const char s2[] = "Blank";
   char *result;
   result = strcoll(s1, s2);
   if(result > 0)
   printf("String s1 is greater than string s2");
   else if(result < 0)
   printf("String s1 is less than string s2");
   else
   printf(" Strings are not same");
   return(0);
}

輸出

String s1 is greater than string s2

更新於: 2020-06-24

201 次瀏覽

開啟你的 職業生涯

完成課程認證

開始學習
廣告