The strcoll () function in C

The function int strcoll (const char * str1, const char * str2) compares strings str1 and str2. The result depends on setting LC_COLLATE.

The function int strcoll (const char * str1, const char * str2) compares strings str1 and str2. The result depends on setting LC_COLLATE.

Declaring the strcoll () function in C

Here is the declaration for strcoll () in C:

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

Parameters

str1 - This is the first string to be compared.

str2 - This is the second string to be compared.

Returns the value

This function returns the following values:

If the value returns <0, this function indicates that str1 is shorter than str2.

If the value returns> 0, this function indicates that str2 is shorter than str1.

If the return value = 0, this function indicates that str1 is equal to str2.

For example

The following C program illustrates the usage of strcoll () in C:

 #include #include int main () { char str1 [ 15 ]; char str2 [ 15 ]; int ret ; strcpy ( str1 , "abc" ); strcpy ( str2 , "ABC" ); ret = strcoll ( str1 , str2 ); if ( ret > 0 ) { printf ( "Chuoi str1 la ngan hon chuoi str2" ); } else if ( ret < 0 ) { printf ( "Chuoi str2 la ngan hon chuoi str1" ); } else { printf ( "Chuoi str1 la bang chuoi str2" ); } return ( 0 ); } 

Compiling and running the above C program will result:

Picture 1 of The strcoll () function in C

According to Tutorialspoint

Previous article: Function strncmp () in C

Next lesson: strcpy () function in C

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile