We can compare stings by using
strcmp() string function.
string1, string2 : Two Input strings for camparison.
We will use this and here is one example.
- 0 : If both strings are equal.
- 1 ( or greater than 1 ) : If length of string1 > length of string2 .
- -1 ( or less than -1 ) : If length of string1 < length of string2 .
The output of above code is here
printf("Output: %d , %d,%d",x,y,z);
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.
strcmp() is case sensitive string comparison so the output of below code is 1 ( not 0 )
char str3="Plus2net"; // Watch the first char P
If the string matches then you will get 0 as output , but if strings are not matching you may get more than 1 or less than -1 as output ( based on difference in string1 and string2 ) depending upon your Operating system.
Example : In place of -1 , you may get -32 or in place of +1 , you may get 55