gpt4 book ai didi

c - 在 Unix 和 Windows 中运行程序

转载 作者:可可西里 更新时间:2023-11-01 14:07:44 27 4
gpt4 key购买 nike

我正在编译一个用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com