strcmp是常见的字符串比较函数,如果两个字符串参数相同,改函数就返回0,否则返回非零值。
看以下程序:
#include<stdio.h>
#include<string.h>
#define ANSWER "Grant"
#define SIZE 40
char * s_gets(char * st, int n);
int main()
{
char try[SIZE];
puts("Who is buried in Grand's tomb?");
s_gets(try, SIZE);
while(strcmp(try,ANSWER)!=0)
{
puts("No,that's wrong.Try again.");
s_gets(try, SIZE);
}
puts("That's right