C examples for stdio.h:fflush
function
<cstdio> <stdio.h>
int fflush ( FILE * stream );
Writing any unwritten data in its output buffer to the file.
Parameter | Description |
---|---|
stream | Pointer to a FILE object that specifies a buffered stream. |
A zero value indicates success.
If an error occurs, EOF is returned and the error indicator is set (see ferror).
#include <stdio.h> char mybuffer[80]; int main()/*from w ww .j a va2 s . com*/ { FILE * pFile; pFile = fopen ("example.txt","r+"); if (pFile == NULL) { perror ("Error opening file"); return -1; } fputs ("test",pFile); fflush (pFile); // flushing or repositioning required fgets (mybuffer,80,pFile); puts (mybuffer); fclose (pFile); return 0; }