Reputation: 10048
I'm currently studying beginner C programming using Eclipse IDE.
Below is a very basic program that suppose to print out a line first, take in some input, and then print out a second line. But my Eclipse always ask me for the input first before printing out the two lines together afterwards.
This is extremely frustrating because it is something so simple and doesn't work. What am I doing wrong?
#include <stdio.h>
int main(void){
int aNumber;
printf("first line\n");
scanf("%d", &aNumber);
printf("second line with %d", aNumber);
return 0;
}
Upvotes: 1
Views: 328
Reputation: 49
Had the same problem once. Solved it by flushing stdout.
#include <stdio.h>
int main(void){
int aNumber;
printf("first line\n");
fflush(stdout); // Prints stdout content
scanf("%d", &aNumber);
printf("second line with %d", aNumber);
return 0;
}
Upvotes: 1