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" );
}
Printable View
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.