缓冲的问题
程序代码:
int main() { int guess =1; printf("Pick an integer from 1 to 100.I will try to guess it\n"); printf("Respond with a y if my guess is right and with\n"); printf("an n if it is wrong.\n"); printf("Uh...is your number %d ?\n",guess); while(getchar()!='y') {printf("Well,then,is it %d\n",++guess); while (getchar()!='\n') printf("xxxxxxx"); continue; } printf("I knew I could do it!\n"); return 0;请帮我解释一下这个代码的循环部分,我的输入次序是n,回车,n其输出如图:
我是这样想的,输入n出现下一句,没有问题,但是我按回车后他是空了一行,显示下面那句,我认为他应该跳出循环了,接下来再按n就将xxxxxx打印出来,很迷惑。
请详细帮我解答一下这个问题,本人小菜。。。。多谢大侠指教。