【发布时间】:2019-11-06 15:24:53
【问题描述】:
我想要一个循环,直到用户按下回车键。
我尝试过使用while(getchar != '\n'){},但是这个服务员每次都输入一个。现在我不知道该怎么做。
do {
clear;//system("cls");
printf("\nPress [enter] to continue");
printf(".");
Sleep(500);
printf(".");//should give a output with press enter to continue... and wait after every point.
Sleep(500);
printf(".");
Sleep(500);
}while(getchar() != '\n');
【问题讨论】:
-
stdin通常是行缓冲的。在输入'\n'之前,getchar()可以使用 Nothing - 即使是第一次调用。也许是一个非标准函数? -
只有 getchar() 部分需要在循环中。
标签: c while-loop getchar