For C-language beginners, the fflush (stdin) function is interpreted as a system function that empties the input buffer, which is once almost half the story, with the progress of computer science, the gradual improvement in the process of learning
1. Why is fflush (stdin) incorrect?First, check the following program:# Include
Int main (void){Int I;For (;;){Fputs ("Please input an integer:", stdout );Scanf ("% d", & I );Printf ("% d/N", I );}Return 0;}This program will first prompt the user
NAMEFflush-flush a StreamSynopsis#include int fflush (FILE *stream);DESCRIPTIONFor output streams, fflush () forces a write of all user-space buffered data for the given output or update stream via the Stream ' s underlying write function.For-input
The following code:
#includeusing namespace std;int main(){ int m; while(1==scanf("%d",&m)) { puts("OK"); } system("pause");}
This code can be a correct loop, that is, the input integer outputs OK, and then waits for the next input to
Reprinted from (http://www.cplusplus.com/reference/clibrary/cstdio/fflush) Int fflush (File * stream );
Flush stream
If the givenStreamWas open for writing and the last I/O operation was an output operation, any unwritten data in the output buffer
Today with
ftruncateTruncation of the file, but how can not achieve the expected effect, truncated after the contents of the file is miscellaneous, and the file size is kept original.
add fflush () and Rewind () after OK.
Here is the test code:
# Include
# Include
# Include
# Include
# Include
Typedef struct com {// char num [10]; long num; char name [10]; Long Count; // char amount [10]; // char from [20]; // char stockdate [10]; struct com * Next;} com; # define Len sizeof
Reprinted from: http://blog.chinaunix.net/u3/99423/showart_2100968.html
I have made many mistakes in the scanf function, and I have also seen mistakes made by others. Remember to remind myself not to repeat the same mistakes. If it is useful to you,
[Php kernel] ---- file system functions are used in common files. Today, I talked to my colleagues about the function of fflush. I thought that the file system function of php should be built on the standard IO Library of the system. therefore, the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.