| Functions | |||||||||||||||||||||||||||||||||||||||||
| Character manipulation | |||||||||||||||||||||||||||||||||||||||||
| Conversions to and from numeric formats | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String manipulation | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String examination | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Memory manipulation | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Miscellaneous | |||||||||||||||||||||||||||||||||||||||||
(C11)(C11) | |||||||||||||||||||||||||||||||||||||||||
Defined in header <string.h> | ||
int strcoll(constchar* lhs,constchar* rhs); | ||
Compares two null-terminated byte strings according to the current locale as defined by theLC_COLLATE category.
Contents |
| lhs, rhs | - | pointers to the null-terminated byte strings to compare |
Collation order is the dictionary order: the position of the letter in the national alphabet (itsequivalence class) has higher priority than its case or variant. Within an equivalence class, lowercase characters collate before their uppercase equivalents and locale-specific order may apply to the characters with diacritics. In some locales, groups of characters compare as singlecollation units. For example,"ch" in Czech follows"h" and precedes"i", and"dzs" in Hungarian follows"dz" and precedes"g".
#include <locale.h>#include <stdio.h>#include <string.h> int main(void){setlocale(LC_COLLATE,"cs_CZ.utf8");// Alternatively, ISO-8859-2 (a.k.a. Latin-2)// may also work on some OS:// setlocale(LC_COLLATE, "cs_CZ.iso88592"); constchar* s1="hrnec";constchar* s2="chrt"; printf("In the Czech locale: ");if(strcoll(s1, s2)<0)printf("%s before %s\n", s1, s2);elseprintf("%s before %s\n", s2, s1); printf("In lexicographical comparison: ");if(strcmp(s1, s2)<0)printf("%s before %s\n", s1, s2);elseprintf("%s before %s\n", s2, s1);}
Output:
In the Czech locale: hrnec before chrtIn lexicographical comparison: chrt before hrnec
(C95) | compares two wide strings in accordance to the current locale (function)[edit] |
| transform a string so that strcmp would produce the same result as strcoll (function)[edit] | |
(C95) | transform a wide string so thatwcscmp would produce the same result aswcscoll (function)[edit] |
| compares two strings (function)[edit] | |
C++ documentation forstrcoll | |