int fflush( FILE *stream );
Parameter:
stream: con trỏ file
Remark:
- Hàm fflush( ) “làm sạch” stream( stdin: đầu vào, stdout: đầu vào).
- Hàm fflush( ) trả về 0, nếu stream được “làm sạch” thành công. Và trả về EOF nếu lỗi xuất hiện.
Ví dụ:
#include "conio.h" #include <stdio.h> 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, sizeof(string) ); printf( "%s\n", string ); } // You must flush the input buffer before using gets. // fflush on input stream is an extension to the C standard fflush( stdin ); printf( "Enter the same sentence with gets: " ); gets(string); printf( "%s\n", string ); getch(); }
Kết quả:
Leave a Reply
You must be logged in to post a comment.