#include<stdio.h>
int main(void)
{
int guess = 1;
char response;
printf("Please pick an integer from 1 to 100. I will try to guess it.\n");
printf("Response with a y if my guess is right and with an n if it is wrong.\n");
printf("Uh... is your number %d?\n", guess);
while ((response=getchar()) != 'y')
{
guess++;
if (response == 'n')
{
printf("Well, then, is it %d?\n", guess);
}
else
{
printf("Sorry, I understand only y or n.\n");
}
while (getchar() != '\n')
{
continue;
}
}
printf("I knew I could do it!\n");
return 0;
}
小while循环的条件改成response != '\n',大循环就会卡住动不了,这是为什么?