strcmpi(): case insensitive string comparison

#include <stdio.h>
#include <string.h>
int main(void){
   char str1[]="Plus2";
   char str2[]="plus2net";
   char str3[]="Plus2net";
   int x,y,z;
   x=strcmpi(str1,str2);
   y=strcmpi(str2,str1);
   z=strcmpi(str2,str3);
   printf("Output: %d , %d,%d",x,y,z);
   return 0;
}
The output of above code is here
-1,1,0
x =-1 because length of str1 is less than length of str2.
y = 1 because length of str2 is greater than length of str1.
z = 0 because length of str2 is equal to length of str3.

strcmpi(string1, string2);
string1, string2 : Two Input strings for camparison.
Output
  • 0 : If both strings are equal.
  • 1 : If length of string1 > length of string2 .
  • -1 : If length of string1 < length of string2 .

strcmpi() is case insensitive string comparison so the output of below code is 0 ( not 1 )
#include <stdio.h>
#include <string.h>
int main(void){
   char str2[]="plus2net";
   char str3[]="Plus2net"; // Watch the first char P 
   int z;
   z=strcmpi(str2,str3);
   printf("Output: %d",z);
   return 0;
}
Output
0
Note : this ignores case of the letter for comparison.

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer