I am trying to compare strings in C with the following code
int strcmp ( const char * str1, const char * str2 );
int main()
{
char name[10];
fgets(name,10,stdin);
if (strcmp(name, "Tom") == 0)
{
printf("Hi, Tom!");
}
else{
printf("You're not Tom!");
}
return 0;
}
However, it will always print “You’re not Tom!” even when I input “Tom” which is confusing. Did I make a mistake?