#printf of does not work before scanf

5 messages · Page 1 of 1 (latest)

lyric slate
#

If I try to run the following simple code under Cygwin on Windows 11:

#include <stdio.h>
int main() {
int i1, i2, sums;

printf( "Enter first integer\n" );
scanf( "%d", &i1 );

printf( "Enter second integer\n" );
scanf( "%d", &i2 );

sums = i1 + i2;
printf( "Sum is %d\n", sums );

return 0;
}

it compiles (via gcc) without a problem, but when I try to execute it, the first statement ("Enter first integer") isn't printed to the terminal, and I have to input two successive numbers (e.g. 3 and 4) before I get:

3
4
Enter first integer
Enter second integer
Sum is 7

drowsy berry
#

I would say it's odd, but what happens if you use cmd.exe instead of eclipse to run your program?

lyric slate
#

mmmmm

#

how can i do it?

drowsy berry
#

I'd just modify the buffering as the first thing in main and call it a day though