Original: http://blog.csdn.net/linux_wgl/article/details/7430561
When writing a C language, the runtime found that scanf than printf first executed, in the Internet to find a bit of information, the original is the output buffer problem. There are two workarounds, first, the buffer is empty, that is, there is no buffer, and second, after each printf execution, the buffer is forced. Here's how:
- Added before printf: setvbuf (stdout,null,_ionbf,0);
The set buffer is empty.
- After each sentence printf is added: Fflush (stdout);
The test code is as follows:
Method One:
#include <stdio.h>intMainvoid) {setvbuf (STDOUT,NULL,_IONBF,0); Charaa[ -]; printf ("Input:"); scanf ("%s", AA); printf ("output:%s", AA); return 0;}
Method Two:
int Main (void) { char aa[]; printf ("input:"); Fflush (stdout); scanf ("%s", aa); printf ("output:%s", aa); Fflush (stdout); return 0 ;}
Problems with scanf prior to printf in eclipse