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");
Use the fflush() function on the stream:
fflush( fp );