Terminal is not synchronized with the program.
This is my simple code to see if it works:
#include <stdio.h>
int main(void){
puts("Hello World!");
system("pause");
return 0;
}
but in the local terminal appears
Press a key to continue...
before
Hello World!
This means that it is not synchronized with the program. How can I solve?
CodePudding user response:
The problem is probably that the output buffer is not getting flushed before the function system
is executed.
In order to explicitly flush the output buffer, you can add the line
fflush( stdout );
immediately before the call to system
.
On most platforms, the standard output stream is line-buffered, so it should not be necessary to flush the output buffer, because puts
automatically adds a newline character to the string, which should cause a line-buffered stream to be automatically flushed. However, according to the information you provided, the standard output stream does not seem to be line-buffered in Eclipse. It seems to be fully-buffered instead.