How to use fflush() function to write all unwritten data in output buffer to file in C

1 Answer

0 votes
#include <stdio.h>
   
int main(void)
{
    char s[64] = "";
	
	FILE *fp = fopen("d:\\data.txt", "r+");

    if (fp == NULL) 
		perror ("Error open file");
    else
    {
		fputs("codeing is fun", fp);
		fflush(fp);
		rewind(fp);
		fgets(s, 63, fp);
		puts(s);
        fclose(fp);
    }
	
    return 0;
}
  
  
/*
run:
  
codeing is fun
 
*/

 



answered May 3, 2016 by avibootz

Related questions

1 answer 165 views
1 answer 282 views
2 answers 243 views
1 answer 261 views
...