在错误的顺序Eclipse的C程序的输出 [英] C program output in wrong order Eclipse

查看:106
本文介绍了在错误的顺序Eclipse的C程序的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了Eclipse进行C语言编程我的Windows机器上,我已经成功地运行一个Hello,World程序。然而,当我试着问用户输入并运行程序基于Eclipse的控制台显示错误的顺序。

I have set up Eclipse for c programming on my Windows machine, I have successfully run a "hello, world" program. However, when I try to ask for user input and run the program the console on Eclipse is displaying in the wrong order.

下面是我

    #include <stdio.h>

    int main(void){

         char letter;

         printf("Please enter a letter:\n");
         scanf(" %c, &letter);
         printf("The letter you have selected is: %c", letter);

         return 0;
    }

这个项目是建立蛮好的,它运行得很好Eclipse之外。但是,当我在Eclipse中运行它,我得到的输出:

This program builds just fine, and it runs just fine outside of Eclipse. But when I run it in Eclipse I get the output:

E <--- (this is my user input)

Please enter a letter:

The letter you have selected is: E

我不知道为什么输出错误的顺序执行的,所以任何帮助将非常AP preciated!谢谢你。

I'm not sure why the output is executing in the wrong order, so any help would be much appreciated! Thank you.

推荐答案

这听起来像Eclipse是缓冲你的程序的输出,而不是显示它的时候了。这表明,跑在Eclipse功能并不打算跑互动节目。

It sounds like Eclipse is buffering the output of your program and not displaying it right away. This indicates that the "run within Eclipse" feature is not intended to run interactive programs.

您可以的尝试的加入 fflush(标准输出); 后的第一个的printf ,但你不应该这样做,只是为了让你的程序工作,在特定的环境。

You could try adding fflush(stdout); after the first printf, but you shouldn't have to do that just to make your program work in a particular environment.

这篇关于在错误的顺序Eclipse的C程序的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆