Mr T. Mr T. - 2 years ago 144
C Question

printf not printing on console

I’m getting started in the C language. I am using eclipse (juno) as my IDE and installed CDT plugin. I have also unpacked mingw64 (GCC Compiler). I wrote a very simple program to see if it works. This is my code:

#include <stdio.h>

int main()
int age;
printf("Hello, please enter your age:\n");
scanf("%d", &age);
printf("Your age is %d", age);
return 0;

The problem is that the output buffer is filled with the string value of the first
but does not output it to the console. I have to enter a number, and only then the buffer pours all the data to the console so I see the console something like this:

Hello, please enter your age:
Your age is 1

instead of what is expected that is:

Hello, please enter your age:
Your age is 1

Now, I found that I can use
after the first
but I don't think that this solution is elegant and even necessary. Any ideas on how I can overcome this?

EDIT - because I'm learning this in my university, I can't use anything that wasn't learned in the course so I can only use

NEW EDIT - I think I have found an explanation for this. As I said, I am outputting to the console view inside Eclipse. The strange thing is that if I compile and run the program from the command line of Windows, I get the wanted result. Therefore, I think that eclipse is actually writing the output to a file and presenting it in the console window. How can I force eclipse to open a real command line window in my run configurations?

Answer Source

OK - apparently this is a known bug of eclipse. This bug is resolved with the resolution of WONT-FIX. have no idea why though. here is the link:
Eclipse C Console Bug

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download