Why the number of lines in data files are different when they are supposed to be same
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Why the number of lines in data files are different when they are supposed to be same

Threaded View

  1. #1
    Join Date
    Apr 2009
    Posts
    30

    Why the number of lines in data files are different when they are supposed to be same

    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.
    Last edited by hajimeml; September 4th, 2011 at 08:28 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center