Question

I have opened a file for writing some data to a file, but it keeps buffering and won't write anything to the file until the program ends. How can I skip the buffering process and write directly to the file.

My code:

fprintf (fp, "# Step: %d  %f\n", ntot, eDiff);
for(i=0; i<nType; i++)  
    fprintf (fp, "%s  %f %f\n",param[i].cTypes, param[i].eps, param[i].sigma);
fprintf(fp, "#  ============\n");
Was it helpful?

Solution

Use the fflush() function on the stream:

fflush( fp );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top