getchar()采用了缓冲区,而getch()才是立即获取,所以要想再用getchar()获取正确的值必须先清空缓冲区,如果是windows操作系统,用fflush(stdin)函数或rewind(stdin)函数,包含在stdio.h头文件中,而在linux下,则使用setbuf(stdin,NULL)函数,同样是stdio.h头文件中。

相关文章:

  • 2021-09-28
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
猜你喜欢
  • 2021-08-03
  • 2022-01-04
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案