关于fflush函数
刚才问问题的时候有个朋友说fflush(stdin)不能保证清空stdin流,是这样吗?他说了以后我才意识到我之前遇到的一些问题也是如此,有时候程序不会出错,但有时就执行语句以后好像总有剩余的数据,输出的东西感觉总多了什么,请问要是用什么办法能将stdin里面的全部清空能?
[解决办法]
while (fgetc(stdin) != '\n');就行了.
这是POSIX规定:
NAME fflush - flush a streamSYNOPSIS #include <stdio.h> int fflush(FILE *stream);DESCRIPTION If stream points to an output stream or an update stream in which the most recent operation was not input, fflush() shall cause any unwritten data for that stream to be written to the file, and the st_ctime and st_mtime fields of the underlying file shall be marked for update.
[解决办法]
http://blog.csdn.net/csu305/article/details/3321084