在 Debug模式下运行此代码时:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("Values entered: %d %d %d\n", a, b, c);
return EXIT_SUCCESS;
}
该程序不会请求任何用户输入,只会输出:
Values entered: 18 78 2130026496
最佳答案
问题似乎是由 GDB
在运行 scanf
之前向 stdin
写入以下行引起的:
18-list-thread-groups --available
并且 scanf("%d%d%d", &a, &b, &c);
将该行解释为 int,而不是等待用户输入。
我当前使用的解决方案是使用以下方法清除程序开头的stdin
:
int ch;
while ((ch = getchar()) != '\n' && ch != EOF);
我知道这是一种黑客攻击,但我搜索了一个多小时寻找解决方案,但找不到任何解决方案。我希望这对某人有帮助。
关于c - Scanf 似乎无法在带有 GDB 的 Eclipse CDT 中以 Debug模式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12126703/