Table of Contents

    strcmpi() Function in C: Case-Insensitive String Comparison

    strcmpi() Function in C: Case-Insensitive String Comparison

    strcmpi() function in C is same as strcmp() function. But, strcmpi( ) function is not case sensitive. i.e, "S" and "s" are treated as same characters. Where as, strcmp() function treats "S" and "s" as different characters.

    Syntax

    int strcmpi ( const char * strng1, const char * strng2 );

    Parameters

    strng1 -first string
    strng2 -Second string

    Returns

    Return Value Description
    Less than zero  strng1 is less than strng2 (strng1 < strng2)
    Greater than zero strng1 is greater than strng2 (string1 > string2)
    Zero strng1 is equal to strng2

    Program

    
    #include <stdio.h>
    #include <string.h>
    int main( )
    {
       char strng1[ ] = "atnyla" ;
       char strng2[ ] = "atatnyla" ;
       int i, j, k ;
       i = strcmpi ( strng1, "ATNYLA" ) ;
       j = strcmpi ( strng1, strng2 ) ;
       k = strcmpi ( strng1, "f" ) ;
       printf ( "\n%d %d %d \n", i, j, k ) ;
       return 0;
    }
    

    Output

    0 1 -1
    Press any key to continue . . .

    Points to be noted

    1. strcmpi() function is non standard function which may not available in standard library in C.
    2. Both functions compare two given strings and returns zero if they are same.