Mega Code Archive

 
Categories / C / Code Snippets
 

Force the buffer contents to be written to the file

//Header: #include <stdio.h> //Declaration: int fflush(FILE *stream); //Return: 0 on success or EOF on error. #include <stdio.h> #include <stdlib.h> int main(void){ FILE *filep; if((filep=fopen("testing", "rb"))==NULL) { printf("Cannot open file.\n"); exit(1); } char ch = 'C'; int j; for(j=0; j<5; j++) { fwrite(ch, sizeof(ch), 1, filep); fflush(filep); } fclose(filep); return 0; }