##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# strcoll

From cppreference.com
< c‎ | string‎ | byte

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.

### [edit] Parameters

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

### [edit] Return value

Negative value if `lhs` is less than `rhs`.

​0​ if `lhs` is equal to `rhs`.

Positive value if `lhs` is greater than `rhs`.

### [edit] Example

Run this code

    #include <stdio.h>
    #include <string.h>
    #include <locale.h>

    int main(void)
    {
        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

### [edit] See also

strcmp | compares two strings (function) [edit]
strncmp | compares a certain amount of characters of two strings (function) [edit]
memcmp | compares two buffers (function) [edit]
C++ documentation for strcoll

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/string/byte/strcoll&oldid=70093"