為什么getchar()不等我在scanf()后按Enter鍵?我正在學(xué)習(xí)C并且我正在使用“getchar()”來停止命令窗口,所以我可以看到練習(xí)正在進(jìn)行但它只是不起作用。下面是一個(gè)樣本:#include <stdio.h>int main(){
int value;
printf("1. option 1.\n2. option 2.\n3. option 3.\n4. Exit\n\nMake an option: ");
scanf("%d", &value);
switch (value)
{
case 1:
printf("you selected the option 1.");
break;
case 2:
printf("you selected the option 2.");
break;
case 3:
printf("you selected the option 3.");
break;
case 4:
printf("goodbye");
break;
default:
printf("thats not an option");
break;
}
getchar();
return 0;}這是輸出:選項(xiàng)1。選項(xiàng)2。選項(xiàng)3。出口。做出選擇:1您選擇了選項(xiàng)1。進(jìn)程返回0(0x0)執(zhí)行時(shí)間:3.453秒按任意鍵繼續(xù)。為什么不等待“getchar()”的輸入?
- 3 回答
- 0 關(guān)注
- 414 瀏覽
添加回答
舉報(bào)
0/150
提交
取消