Sunday, April 28, 2013

strcmpi()

This is function is same as strcmpi() aspect it is not case sensitive. 

This function compare two strings to find out whether they are same or different.

The two string are compared character by character until there is a mismatch or end of one of the strings is reached, whichever occurs first.

If the two strings are identical, strcmpi() return zero.
If they are not, it returns the numeric difference between the ASCII values of the first non-matching pair of characters.

In summarize:
(Compare ASCII values of string's characters)
if both string equal = 0
if first string > second string = +ve
if first string < second string = -ve

syntax:

strcmpi("first_sting","second_string");

example:

strcmpi("ABC","abc");
[Here, 
first comparison: A==a
second comparison: B==b
Thired comparison: C==c
So result = 0]

illustrate strcmpi() C program:

/*c program for illustrate strcmpi() function*/
#include<stdio.h>
int main()
{
 int r;
 char str1[40],str2[40];
 printf("Enter first string : ");
 gets(str1);
 printf("Enter second string : ");
 gets(str2);
 r = strcmpi(str1,str2);
 printf("Result : %d",r);
 getch();
 return 0;
}

The output of above program would be:


output for strcmpi() function uses in C program
Figure: Screen shot for strcmpi() function uses in C program


Related program:

  1. List of standard library function

No comments:

Post a Comment