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 prog
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.
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.
Yeah, Eclipse will buffer a certain amount of output (I don't remember how much off hand) before it will appear in the output window. Eclipse is communicating with the attached process through a pipe which is fully buffered. It won't flush until either fflush()
is called or the buffer is full. I found that when debugging with Eclipse, things work best if I put the following near the beginning of my application:
setvbuf(stdout, NULL, _IONBF, 0);
This will cause stdout
to flush immediately whenever it is written to. If you want to use that for debugging and turn it off otherwise, you can conditionally compile it:
#ifdef DEBUG
setvbuf(stdout, NULL, _IONBF, 0);
#endif
No need to put fflush()
everywhere this way.
Here's where I found the solution when I first ran into this issue myself.
http://wiki.eclipse.org/CDT/User/FAQ#Eclipse_console_does_not_show_output_on_Windows
Eclipse's console is not a true console or terminal but rather eclipse is communicating with the attached process through a pipe which is fully buffered not line buffered. This is why a newline '\n' does not cause the buffer to be flushed.
Try adding fflush(stdout);
after the first printf
. This has a decent chance of being of help, in case Eclipse does not auto-flush after '\n'
.
Yes, fflush()
ing buffers is necessary to keep the console's screen updated ...
... but please guys, it's not Eclipse's fault in- and output might get out of sync, but the library's in use!