This line
if(strstr(sentence,word) == 0)
should be
if(strstr(sentence,word) != NULL)
strstr()
returns a pointer to the first occurence of word
in sentence
or NULL
if the word was not found.
For details please read here.
Also using fgets()
to read in the "strings" appends a '\n'
to the end of the "strings". This prohibits successful comparsion.
To chop of the trailing '\n'
you could do like this:
fgets(word, sizeof(word), stdin);
{
size_t size = strlen(word);
if (size && ('\n' == word[size-1]))
{
word[size-1] = '\0';
}
}