The console output is displayed in the wrong order.

I am using win 8.1 64bit Eclipse Luna 4.4.0 and compiling with gcc 4.6.4 and the problem, for example,

in this simple program, mine operators printfand scanfappear on the console in the wrong order.

#include <stdio.h>
#include <stdlib.h>

int main(void) {

    int i;

    printf("Enter int: ");
    scanf("%d",&i);
    printf("Hello %d\n",i);

    return EXIT_SUCCESS;
}

he does this:

4

Enter int: Hello 4

instead of this:

Enter int: 4

Hi 4

+4
source share
1 answer

printfbuffered 1 . This means that when you call it, it will not be printed immediately. Instead, it will save what you told it to print, and automatically print it when enough text is saved in the buffer.

\n , ( printf ). fflush

printf("Enter int: "); fflush(stdout);
scanf("%d",&i);
printf("Hello %d\n",i);

1 , stdout, , , printf .

+3

All Articles