From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/string%2Fbyte%2Fstrcoll.html | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 devdocs/c/string%2Fbyte%2Fstrcoll.html (limited to 'devdocs/c/string%2Fbyte%2Fstrcoll.html') diff --git a/devdocs/c/string%2Fbyte%2Fstrcoll.html b/devdocs/c/string%2Fbyte%2Fstrcoll.html new file mode 100644 index 00000000..8c19e000 --- /dev/null +++ b/devdocs/c/string%2Fbyte%2Fstrcoll.html @@ -0,0 +1,60 @@ +

strcoll

Defined in header <string.h>
int strcoll( const char* lhs, const char* rhs );
+

Compares two null-terminated byte strings according to the current locale as defined by the LC_COLLATE category.

+

Parameters

+ +
lhs, rhs - pointers to the null-terminated byte strings to compare

Return value

Notes

Collation order is the dictionary order: the position of the letter in the national alphabet (its equivalence 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 single collation units. For example, "ch" in Czech follows "h" and precedes "i", and "dzs" in Hungarian follows "dz" and precedes "g".

+

Example

#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");
+ 
+    const char* s1 = "hrnec";
+    const char* s2 = "chrt";
+ 
+    printf("In the Czech locale: ");
+    if (strcoll(s1, s2) < 0)
+        printf("%s before %s\n", s1, s2);
+    else
+        printf("%s before %s\n", s2, s1);
+ 
+    printf("In lexicographical comparison: ");
+    if (strcmp(s1, s2) < 0)
+        printf("%s before %s\n", s1, s2);
+    else
+        printf("%s before %s\n", s2, s1);
+}

Output:

+
In the Czech locale: hrnec before chrt
+In lexicographical comparison: chrt before hrnec

References

See also

+ + + + +
+
(C95)
compares two wide strings in accordance to the current locale
(function)
transform a string so that strcmp would produce the same result as strcoll
(function)
+
(C95)
transform a wide string so that wcscmp would produce the same result as wcscoll
(function)
compares two strings
(function)
C++ documentation for strcoll
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/string/byte/strcoll +

+
-- cgit v1.2.3