Ok...I am a newbie at c programming, so i know i am stupid.
what is the solution to a problem like this?
-------------------------------
char name;
scanf("%s", &name);
if (name=="Bob") printf("Your name is bob");
-------------------------------
How would i could i compare strings?
Pleeeaaase someone help me!
Comments
: Ok...I am a newbie at c programming, so i know i am stupid.
:
: what is the solution to a problem like this?
:
:
:
: -------------------------------
[code]
char name[80];
fgets(name,sizeof(name)-1,stdin);
if (strcmp(name,"Bob") == 0)
printf("Your name is %s
", name);
[/code]
: -------------------------------
:
: How would i could i compare strings?
: Pleeeaaase someone help me!
:
:
Thanks a bunch!
[/code]
:
: what is the solution to a problem like this?
:
:
:
: -------------------------------
: char name;
: scanf("%s", &name);
: if (name=="Bob") printf("Your name is bob");
: -------------------------------
:
: How would i could i compare strings?
: Pleeeaaase someone help me!
:
:
There is a function defined in viz strcmp
eg:
if (strcmp(name1, "Bob") == 0) {
printf("Name is Bob
");
}
Note that this is case-sensitive. If u want case-insensitive use
strcasecmp.