Issue
I have the following simple code in C language:
#include <stdio.h>
int main(){
printf("Give an integer:\n");
int x;
scanf("%d",&x);
printf("10*%d=%d\n",x,10*x);
return 0;
}
Using CodeBlocks IDE it is executed in the right order but when I use Eclipse IDE it jumps to the scanf command and then prints the messages as it should. Can anyone explain this?
Thank you in advance
Solution
Usually stdout
is set to line buffered. Apparently one of your IDEs sets it to fully buffered.
You can force prints to dump the associated buffer with fflush()
, eg
printf("hello "); // works in unbuffered stream
printf("world!\n"); // works in line buffered stream
fflush(stdout); // works in fully buffered stream
Answered By - pmg