strcoll function(String Compare Using Locale-Specific Collating Sequence) in C Language – example and detail

In the C Programming Language, the strcoll function returns a negative, zero, or positive integer depending on whether or not the object pointed to through s1 is much less than, equal to, or increased than the object pointed to through s2.

The strcoll feature performs the assessment primarily based on the rules of the current locale’s LC_COLLATE category.


The syntax for the strcoll feature in the C Language is:

int strcoll(const char *s1, const char *s2);

Parameters or Arguments


An array to compare.


An array to compare.


The strcoll function returns an integer. The return values are as follows:

Return Value Explanation 0 s1 and s2 are equal Negative integer The stopping persona in s1 was much less than the stopping persona in s2 Positive integer The stopping persona in s1 was greater than the stopping character in s2

Required Header

In the C Language, the required header for the strcoll feature is:

#include <string.h>

Applies To

In the C Language, the strcoll characteristic can be used in the following versions:

ANSI/ISO 9899-1990

strcoll Example

Let’s look at an example to see how you would use the strcoll function in a C program:

/* Example using strcoll by */

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

int main(int argc, const char * argv[])
    /* Create a place to store our results */
    int result;

    /* Create two arrays to hold our data */
    char example1[50];
    char example2[50];

    /* Copy two strings into our data arrays */
    strcpy(example1, "C strcoll is a string function");
    strcpy(example2, "C strcoll at");

    /* Compare the two strings provided using locale-specific collating sequence */
    result = strcoll(example1, example2);

    /* If the two strings are the same say so */
    if (result == 0) printf("Strings are the same\n");

    /* If the first string is greater than the second say so
     (This is because the 'i' in the word 'is' is greater than
     the 'a' in the word 'at' */
    if (result > 0) printf("Second string is greater than the first\n");

    return 0;

When compiled and run, this software will output:

Second string is greater than the first

Similar Functions

Other C functions that are similar to the strcoll function:

memcmp characteristic strcmp function strncmp feature

See Also

Other C features that are noteworthy when dealing with the strcoll function:

strxfrm function <string.h>