I found a nice example of how to use strcmp, but it's only working with fgets(), and i need to make it work with scanf. So, here's the code:
int main(void) {
char fruit[] = "apple\n";
char ans[80];
do {
printf ("Guess my favorite fruit? ");
scanf ("%s",ans);
} while (strcmp (fruit, ans) != 0);
puts ("Correct answer!");
return 0;
}
Even when I write the correct answear ("apple") it stays in the loop and keeps asking me what is the favorite fruit... I'm guessing it has something to do with the chars that are not written at ans[80](I need it to be a char array with 80chars at max). I'm not getting this...
Thanks in advance.