int strcmp ( const char * str1, const char * str2 );
<0
0
>0
123456789101112131415
#include <stdio.h> #include <string.h> int main () { char key[] = "apple"; char buffer[80]; do { printf ("Guess my favorite fruit? "); fflush (stdout); scanf ("%79s",buffer); } while (strcmp (key,buffer) != 0); puts ("Correct answer!"); return 0; }
Guess my favourite fruit? orange Guess my favourite fruit? apple Correct answer!