清除文件缓冲区,文件以写方式打开时将缓冲区内容写入文件 ]
原型: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
阅读(1256) | 评论(0) | 转发(0) |