为什么getchar()不等我在scanf()后按Enter键?
我正在学习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()”的输入?
 aluckdog
aluckdog 随时随地看视频慕课网APP
随时随地看视频慕课网APP
相关分类