I use the library ncursesin C project and ran into a problem using printf()/ puts()after cursing and initializing . Here is a simplified illustration:
initscr();
endwin();
puts("first");
usleep(1e6);
puts("second");
Both firstand secondwill appear on the screen just after the executable file will (a little more than one second), instead of having to first print firstand then, after a second second. ncursesit seems to buffer stdoutsomehow and only flush it when exiting. fflush(stdout)seems to solve the problem:
initscr();
endwin();
puts("First.");
fflush(stdout);
usleep(1e6);
puts("Second");
stdout , ( ). puts() usleep() , fflush(stdout) , , , , , .