同样一个程序:
#include
想实验下printf的缓冲,于是写了下面一小段代码
#include
为测试输入缓冲清空,代码test.c如下:
#include
Remarks The fflush function flushes a stream. If the file associated with stream is open for output, fflush writes to that file the contents of the buffer associated with the stream. If the stream is open for input, fflush clears the contents of the buffer. fflush negates the effect of any prior call to ungetc against stream. Also, fflush(NULL) flushes all streams opened for output. The stream re...
As we known that fflush(3) is a standard C library function. So it should be has the same behavior on any platforms which support standard ansi C library. But when I wrote fflush(stdin); Windows will discard all things stored in the system's standard input buffer. So when I issue getchar(3) next fflush(3), I could get correct character I wish. FreeBSD, contrasted with windows, has not the effe...
redhat AS3下,用ffush(stdin)好像不起作用艾。同样的程序放到windows平台下用vc+proC运行完全没有问题;但在redhat+PROC下(编译也没有问题)运行时输入缓冲区老有问题,好像fflush(stdin)不起作用一样。请教大家unix下如何清除缓冲区! 以下代码在linux上运行输入字母时出现死循环,在windows下就不会出现。 #include "stdio.h" main() { int action; for(;;) { printf("\n 1 :Query,"); printf(" 2 :Insert,"); printf(" ...