strcmp( ) function in c

strcmp function in c which compares two strings to find out whether they are same or different. The two strings 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, strcmp( ) returns a value zero. If they’re not, it returns the numeric difference between the ASCII values of the first non-matching pairs of characters

Example strcmp( ) function

main( )
{
char string1[ ] = “Jerry” ;
char string2[ ] = “Ferry” ;
int i, j, k ;
i = strcmp ( string1, “Jerry” ) ;
j = strcmp ( string1, string2 ) ;
k = strcmp ( string1, “Jerry boy” ) ;
printf ( “\n%d %d %d”, i, j, k ) ;
}

Output of this

0 4 -32

Leave a Comment