char *word[128];
fgets(word, 128, stdin);
if(word == "hello")
printf("You entered hello as your word.");
So basically I am trying to get user input as a string and then use the following comparison so see if the string the user entered is equal to "hello". however, when compiling this code, it doesn't work. What did I do wrong?
EDIT: So based on feedback so far this is what I have:
char word[128];
fgets(word, 128, stdin);
if(strcmp(word, "Hello") == 0)
printf("match\n");
However, when I compile and run this program and enter Hello it does not print "match".
==
is not how string comparisons are done in C. Usestrcmp
.char *word[128]
should bechar word[128]
. That plusstrcmp
should work.