#include
#include
int main()
{
char string1[] = "bird";
char string2[] = "sky";
char string3[] = "bird";
int result;
//comparing first and second string
result = strcmp(string1,string2);
printf("strcmp(string1, string2) = %d\n", result);
// comparing first and third strings
result = strcmp(string1,string3);
printf("strcmp(string1, string3) = %d\n", result);
return 0;
}
Here we used strcmp() function to compare two string .Well,
you should know that,if the 2 string matches with each other then the function will return 0.
On the otherhand..if they don't match then the function will return 1..
Returning 1,in this case,,if the two strings are totally different word,,then the function will return (-1)
and if the 2 strings are same word but,,there is difference between uppercase and lower case letter,,then the
function will return (1). Thats why I've given 2 examples here..If you try these two programs you will get clear idea.
And we took and integer type variable named result to store the returned value of strcmp() function.
#include
#include
int main()
{
char string1[] = "bird";
char string2[] = "birD";
char string3[] = "bird";
int result;
//comparing first and second string
result = strcmp(string1,string2);
printf("strcmp(string1, string2) = %d\n", result);
// comparing first and third strings
result = strcmp(string1,string3);
printf("strcmp(string1, string3) = %d\n", result);
return 0;
}
Quote: