fflush函数

1310阅读 0评论2013-01-26 paulscholes007
分类:LINUX

清除文件缓冲区,文件以写方式打开时将缓冲区内容写入文件 ]
原型:int fflush(FILE *stream)
用法:
/* FFLUSH.C */

#include
#include

void main( void )
{
int integer;
char string[81];

/* Read each word as a string. */
printf( "Enter a sentence of four words with scanf: " );
for( integer = 0; integer < 4; integer++ )
{
scanf( "%s", string );
printf( "%s\n", string );
}

/* You must flush the input buffer before using gets. */
fflush( stdin );
printf( "Enter the same sentence with gets: " );
gets( string );
printf( "%s\n", string );
}


输出:

Enter a sentence of four words with scanf: This is a test
This
is
a
test
Enter the same sentence with gets: This is a test
This is a test
 
上一篇:fgets 之用法
下一篇:fflush和fsync的一些总结