Hello. I have a C program which does simulation and saves the data into five different data files at each iteration of a while loop. However, when I stopped the program, I noticed that the files have different number of lines while they are supposed to be the same. This happens all the time. I can imagine that there may be a line difference if I terminated the program in the middle of the loop. However, it seems that the longer I let the program runs before force termination, the more the difference in the number of lines. It looks like that the files are divided into two groups, files1, files3, files4 have X lines while files 2 and files5 have Y lines. For example, three of the files have 12345 lines while the other two have 12912 lines. Anybody knows what is going on and how to resolve the issue? I read that sometimes the data are in the buffer before being written to a file. I already added a fflush command immediate behind each fprintf statement. Do I need any other command besides fflush? e.g. fprintf(outfile3, "%g %g %g \n", a, b, c); fflush(outfile3); : : fprintf(outfile4, "%d %g %d \n", d, e, f); fflush(outfile4); As I force terminate the program each time, I do not fclose the files. Is this the problem? I am running the program under Mac OS X Snow Leopard. I use gcc to compile. Thanks.