• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C/C++ -> Reading Binary Files

noninterleaved

Senior member
I am trying to read a binary file using c or c++ and store the bytes into an int. Here is what I am trying to do...

#define BUFF_SIZE sizeof(int)

char buffer[BUFF_SIZE];
int i;
int binNumber;
hFile = _open(fileName, _O_BINARY);

// read the file little-endian style for x86 architecture
for(i = 1; i <= BUFF_SIZE; i++)
{ read(hFile, &amp;buff[BUFF_SIZE - i], 1); }

// now try to convert the bytes to an int (here is the trouble!!)
binNumber = * (int *)(buff)



now the binNumber never comes out right... anyone know what is wrong??

I am trying to read binary files from a SOLARIS/SpARC machine, that is why I have to flip all the bits backwards like that... I think the problem is in the cast... Anyone who has any experience doing this know the solution??? Thanks!!





 
i meant buffer...

anyways... I figured it out, the spec for the file was unclear, so I kept changing types until i figured it out...

thanks anyways.
 
Back
Top