#include <stdio.h>
#include <string.h>
int main()
{
char string1[] = "Abc";
char string2[] = "Abc";
int result = strcmp(string1, string2);
if(result == 0)
{
printf("These string are the same ");
}
else
{
printf("These string are not the same ");
}
printf("%d", result);
return 0;
}
I expected the output would be "These string are the same", but it printed out with 0 at the end of the statement. Ex : These string are the same 0. How can I get rid of the number?
>Solution :
You are printing
printf("These string are the same ");
and then
printf("%d", result);
The latter prints the integer value of "result" which is ‘0’ (the result of the comparison)