c - 在 Unix 和 Windows 中运行程序

标签 c windows eclipse unix

我正在编译一个用 C 编写的简单程序,并且在 Windows 7 和我的 MacBook Pro 上都使用 Eclipse 作为 IDE。我的 friend 写了一个非常简单的程序,让我帮助他:

int a = 0;
char b[2];
printf("Input first class info:\n");
printf("Credit Hours: \n");
scanf("%d", &a);
printf("Letter Grade: ");
scanf("%s", b);

所以当我在我的 mac 上运行它时,每一行都会打印出来,当我遇到 scanf() 时,我可以输入并按预期继续。在 Windows 中,我必须输入所有内容,然后它会打印所有行。我不确定为什么会这样……这里的 Windows 和 Mac 有什么区别?

麦克:

Input first class info:
Credit Hours: 4
Letter Grade: B+

Windows :

4
B+
Input first class info:
Credit Hours:
Letter Grade:

谢谢, 赫里斯托

最佳答案

this thread 所述在 Windows 上:

You need to fflush(stdout) after your call to printf().

另外,因为 bug 27663 ,在 printf() 的缓冲区变满之前,对 Eclipse 控制台执行 printf() 不会刷新。
Windows 控制台有各种相关的错误:bug 102043bug 121454 .

关于c - 在 Unix 和 Windows 中运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2816031/

相关文章:

c - 均匀缩放一个字节的最佳方法是什么?

c - 在从未更改的枚举上切换大小写

用于 clojure 开发的 Linux 与 Windows

windows - 在 Windows 资源管理器上下文菜单中添加分隔符(不在子菜单中)

java - 在 Eclipse 中调试 JUnit 测试断点不起作用

eclipse - Eclipse 中不考虑 Maven 配置文件

c - 用于编译 C 文件的 emacs 键绑定(bind)

c - Code Jam 第 1A 轮 ProblemA 的 C++ 中的二分搜索

c# - 为什么我的 Windows C# 服务崩溃?

java - 如何在 RAD/Websphere 8.5 中进行热代码替换