🔧 文字列 ・ string.h ・ C89
strcoll の使い方int strcoll(const char *s1, const char *s2);
現在のロケール設定に従って2つの文字列を比較する。日本語や各国語の並び順(照合順序)を考慮した比較が必要な場合に、単純なバイト比較のstrcmpの代わりに使う。 ロケールが"C"(既定)のままだとstrcmpと同じ結果になるため、実際に効果を出すにはsetlocaleが必須。
#include <string.h>
#include <locale.h>
#include <stdio.h>
int main(void) {
setlocale(LC_COLLATE, "");
printf("%d\n", strcoll("apple", "banana"));
return 0;
}
アプリの関数リファレンスで引く(無料・登録不要) 関数一覧へ
strcoll と一緒に使う関数memcmp
memcpy
memmove
memset
memset_explicit
strcat
strchr
strcmp
strcpy
strcspn
strdup
strerror
strlen
strncat
strncmp
strncpy
もっと先へ:ポインタ・メモリ・ファイル入出力・セキュアコーディングを含む全26トラックと、段位検定・模試のフルセットは完全版に収録しています。