strcoll() is a built-in library function and is declared in <string.h> header file. This function compares the string pointed to by str1 with the one pointed by str2.The strcoll() function performs the comparison based on the rules of the current locale’s LC_COLLATE category.
Syntax:
int strcoll(const char *str1, const char *str2)
Parameters: Function strcoll() takes two strings as parameters and returns an integer value.
Value Meaning less than zero str1 is less than str2 zero str1 is equal to str2 greater than zero str1 is greater than str2
- less than zero : When str1 is less than str2
// C program to illustrate strcoll()#include <stdio.h>#include <string.h>intmain(){charstr1[10];charstr2[10];intret;strcpy(str1,"geeksforgeeks");strcpy(str2,"GEEKSFORGEEKS");ret =strcoll(str1, str2);if(ret > 0) {printf("str1 is greater than str2");}elseif(ret < 0) {printf("str1 is lesser than str2");}else{printf("str1 is equal to str2");}return(0);}chevron_rightfilter_noneOutput:
str1 is greater than str2
- greater than zero :when str1 is greater than str2
// C program to illustrate strcoll()#include <stdio.h>#include <string.h>intmain(){charstr1[10];charstr2[10];intret;strcpy(str1,"GEEKSFORGEEKS");strcpy(str2,"geeksforgeeks");ret =strcoll(str1, str2);if(ret > 0) {printf("str1 is greater than str2");}elseif(ret < 0) {printf("str1 is lesser than str2");}else{printf("str1 is equal to str2");}return(0);}chevron_rightfilter_noneOutput:
str1 is lesser than str2
-
Is equal to zero : when str1 is equal to str2
// C program to illustrate strcoll()#include <stdio.h>#include <string.h>intmain(){charstr1[10];charstr2[10];intret;strcpy(str1,"GEEKSFORGEEKS");strcpy(str2,"GEEKSFORGEEKS");ret =strcoll(str1, str2);if(ret > 0) {printf("str1 is greater than str2");}elseif(ret < 0) {printf("str1 is lesser than str2");}else{printf("str1 is equal to str2");}return(0);}chevron_rightfilter_noneOutput:
str1 is equal to str2
Related Function : strcmp(), memcmp()
This article is contributed by Shivani Ghughtyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Bug Tracking System
- C Program to sort rows of the Matrix
- Order of execution in initializer list in C++
- Unusual behaviour with character pointers
- Header Guard in C++
- Advantages and Disadvantages of Array in C
- Can we write a print statement within if parentheses?
- If memory allocation using new is failed in C++ then how it should be handled?
- Draw an ellipse divided by straight line into two colored part in C++ Graphics
- Types of C files after its compilation
- What happens if we mix new and free in C++?
- How to find arctangent with Examples
- VS Code | Build, Run and Debug in C++
- VS Code | Compile and Run in C++

