I'm coming from Python and there you can easily compare two strings (char arrays) like that:
if "foo" == "bar":
# ...
How would I do this in C? I already saw this post but it didn't work.
Code:
int main(void) {
char string[100];
printf("Please enter something: ");
fgets(string, 100, stdin);
if (strcmp(string, "a") == 0)
printf("a");
else if (strcmp(string, "b") == 0)
printf("b");
else if (strcmp(string, "c") == 0)
printf("c");
else
printf("something else");
return (0);
}
It prints "something else" though I entered a
.