Easy Tutorial
❮ C Examples Printf Char C Function Memchr ❯

C Library Function - strcoll()

C Standard Library - <string.h>

Description

The C library function int strcoll(const char *str1, const char *str2) compares the strings str1 and str2, with the result dependent on the LC_COLLATE locale setting.

Declaration

Here is the declaration for the strcoll() function.

int strcoll(const char *str1, const char *str2)

Parameters

Return Value

The function returns the following values:

Example

The following example demonstrates the use of the strcoll() function.

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

int main ()
{
   char str1[15];
   char str2[15];
   int ret;

   strcpy(str1, "abc");
   strcpy(str2, "ABC");

   ret = strcoll(str1, str2);

   if(ret > 0)
   {
      printf("str1 is greater than str2");
   }
   else if(ret < 0) 
   {
      printf("str2 is less than str1");
   }
   else 
   {
      printf("str1 is equal to str2");
   }

   return(0);
}

Let's compile and run the above program, which will produce the following result:

str1 is greater than str2

C Standard Library - <string.h>

❮ C Examples Printf Char C Function Memchr ❯