我正在学习C语言,使用"getchar()"来停止命令窗口以便能够查看我正在执行的练习,但它不起作用。以下是一个示例:
#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;
}
这是输出结果:
- 选项1。
- 选项2。
- 选项3。
- 退出。
请选择一个选项:1
您选择了选项1。
进程返回0(0x0),执行时间为3.453秒
按任意键继续。
为什么它不等待“getchar()”的输入?