Empties a stream's buffer to the storage device.
#include <stdio.h> int fflush(FILE *stream);
stream
A pointer to a file stream.
The fflush() function empties stream's buffer to the file associated with stream. If the stream points to an output stream or an update stream in which the most recent operation was not input, the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file; otherwise the behavior is undefined.
The fflush() function should not be used after an input operation. Using fflush() for input streams especially the standard input stream ( stdin) is undefined and is not supported and will not flush the input buffer.
This facility may have limited capability on configurations of the EWL that run on platforms that do not have console input/output or a file system.
The function fflush() returns EOF if a write error occurs, otherwise it returns zero.
#include <stdio.h> #include <stdlib.h> int main(void) { FILE *f; int count; // create a new file for output if (( f = fopen("foofoo", "w")) == NULL) { printf("Can't open file.\n"); exit(1); } for (count = 0; count < 100; count++) { fprintf(f, "%5d", count); if( (count % 10) == 9 ) { fprintf(f, "\n"); fflush(f); /* flush buffer every 10 numbers */ } } fclose(f); return 0; } Output to file foofoo: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99