为了账号安全,请及时绑定邮箱和手机立即绑定

为什么getchar()不等我在scanf()后按Enter键?

为什么getchar()不等我在scanf()后按Enter键?

C
aluckdog 2019-09-14 15:11:04
为什么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()”的输入?
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 377 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信