我是 C 的新手,我正在学习一些教程,但在 CLion 中运行代码时我总是遇到错误。
每当我使用 scanf
时,它似乎总是重复控制台中的前一行。
这是它输出的内容:
Please enter your first number:5
Please enter your first number: 5
Please enter your second number:6
Please enter your second number: 6
5 < 6
Process finished with exit code 0
这是我认为它应该输出的内容:
Please enter your first number:5
Please enter your second number:6
5 < 6
Process finished with exit code 0
当然,这是我的代码:
#include <stdio.h>
int main()
{
int no1;
int no2;
printf("Please enter your first number: ");
scanf(" %d", &no1);
printf("Please enter your second number: ");
scanf(" %d", &no2);
if(no1 < no2){
printf("%d < %d", no1, no2);
} else if (no1 == no2) {
printf("Both numbers are %d", no1);
} else {
printf("%d > %d", no1, no2);
}
return 0;
}
我也在使用 MinGW 3.21、CMake 3.5.1
编辑: 我只是在普通命令行上运行代码,发现这不是问题。它似乎只是 CLion 的控制台。
最佳答案
这是 CLion 控制台中的错误 - CPP-2580 有两种可能的解决方法:
- 关闭 PTY:通过禁用注册表中的 run.processes.with.pty 选项(帮助 -> 查找操作 -> 注册表...)
- 使用 Cygwin 而不是 MinGW
关于Clion scanf 复制上一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37514177/