Where am i going wrong?
printf executes with any input.
Code:int main( ) { char name[10]; scanf ("%s", name); if("name==bob")printf ("nice name" ); }
Where am i going wrong?
printf executes with any input.
Code:int main( ) { char name[10]; scanf ("%s", name); if("name==bob")printf ("nice name" ); }
"name==bob" is a string. That string exists, therefore it is true, therefore the true part of the if statement happens.
One, if you wanted to do == you wouldn't put the whole thing in quotes, and two, you can't use == to compare strings anyway (instead: strcmp).
CoCo,
Use strcmp() for that.
Code:if(!strcmp(name, "bob")) printf(...);
That Great. Can I use strcmp to compare multiple strings
There are 5 different names which when entered must display different messages
Then you're probably going to need 5 different calls to the strcpy function to account for each case.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens