// strcmp example // Compare two strings. // source: http://www.cplusplus.com/ #include #include #include #define SIZE 80 int main() { char fruit[] = "apple\n"; char guess[SIZE]; do { printf("Guess my favorite fruit? "); // fgets retains the /n character hence the initialization // of char fruit[] = "apple\n"; fgets(guess, sizeof(guess), stdin); } while (strcmp(fruit, guess) != 0); fprintf(stdout, "Correct answer! i like %s", guess); return EXIT_SUCCESS; }