CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    May 2001
    Location
    US,NY
    Posts
    25

    How to read blocks of float[15] from a binary file???

    I thought the following would read in blocks of 15 floats from a binary file but after a bunch of correct reads all the output numbers are giberish, numbers like 1E-20 type stuff..

    I have to use stdio routines like fread, I have written the same code with fstreams and it works fine. I am missing some stdio quirk or something.. It seems to get hosed when the _cnt variable in the FILE structure becomes < then the size of 15 floats (60).. I believe it has to do with the buffering of the file, which is the system 4096 size.

    I have done more debugging.. _cnt gets to a value of 1 then the next fread reads data that is 1516 bytes downstream instead of 60 (note that this is not even a multiple of 60, my block size).. for no reason, I have no seeks or anything in the code..

    float CPDATA[15];
    do{
    fread((char*)CPDATA,sizeof(float)*15, 1, thO->fd);
    //outfile read info to a file
    outfile<<ftell(thO->fd)<<" ";
    for(int i=0;i<15;i++)
    outfile<<CPDATA[i]<<" ";
    outfile<<endl;

    k++;
    }while(k<j);
    Last edited by delic; November 2nd, 2002 at 04:44 PM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured