BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C strcoll() Function – C tutorial

Last Updated: September 11, 2022 by Chaitanya Singh | Filed Under: c-programming

The strcoll() function is similar to strcmp() function, it compares two strings and returns an integer number based on the result of comparison.

C strcoll() declaration

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

str1 – First String
str2 – Second String

Return value of strcoll()

  • > 0 if the ASCII value of first unmatched character in string str1 is greater than str2.
  • < 0 if the ASCII value of first unmatched character in string str1 is less than str2.
  • =0 if both strings are equal

C strcoll() function example

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

int main () {
   char str1[20];
   char str2[20];
   int result;

   strcpy(str1, "HELLO");
   strcpy(str2, "hello world!");

   result = strcoll(str1, str2);

   if(result > 0) { 
      printf("ASCII value of first unmatched character of str1 is greater than str2");
   } else if(result < 0) {
      printf("ASCII value of first unmatched character of str1 is less than str2");
   } else {
      printf("Both the strings str1 and str2 are equal");
   }

   return 0;
}

Output:

ASCII value of first unmatched character of str1 is less than str2

In this example we are comparing two strings that are different. The strcoll() function is case sensitive. The ASCII value of ‘H’ is less than ‘h’ which is why this function returns negative value.
If we reverse the arguments in the strcoll() function, lets say strcoll(str2, str1) then the function would return a positive value.

Related Posts:

  1. C – strcat() function
  2. C – strchr() function
  3. C – strncat() function
  4. C – strncmp() function

Top Related Articles:

  1. C strcmp() Function with example
  2. C – loops in C programming with examples
  3. C strchr() Function with example
  4. C strncmp() Function with example
  5. C strcpy() Function – C tutorial

Tags: C-Library, C-String

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

C Programming Tutorial

  • C Tutorial
  • History of C
  • Features of C
  • Turbo C++ installation
  • First C Program
  • printf scanf
  • Variables in C
  • Data Types in C
  • C - Keywords
  • C Identifiers
  • C Comments
  • Operator precedence
  • C - if statement
  • C - if..else
  • C - for loop
  • C - while loop
  • C - do while loop
  • C - continue
  • C - break statement
  • C - switch..case
  • C - goto statement
  • C - Arrays
  • 2 D array
  • C - String
  • C - functions
  • Function call by reference
  • Function call by value
  • Array to function
  • C - Structures
  • C - Pointers
  • Pointer to Pointer
  • Pointers to functions
  • C - function pointers
  • Pointer & Array
  • C - File I/O
  • C Programming Examples

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap