strcoll() in C/C++

CC++Programming

The function strcoll() is used to compare two strings using locale - specific collating sequence.

It returns −

  • zero, when both strings are same,
  • greater than zero value when first string is greater than other
  • less than zero value, when first string is less than other.

Here is the syntax of strcoll() in C language,

int strcoll(const char *first_string, const char *second_string);

Here is an example of strcoll() in C language,

Example

 Live Demo

#include <stdio.h>
#include <string.h>
int main () {
   const char s1[] = "Helloworld";
   const char s2[] = "Blank";
   char *result;
   result = strcoll(s1, s2);
   if(result > 0)
   printf("String s1 is greater than string s2");
   else if(result < 0)
   printf("String s1 is less than string s2");
   else
   printf(" Strings are not same");
   return(0);
}

Output

String s1 is greater than string s2
raja
Published on 08-Oct-2018 15:13:19
Advertisements