Opening an unknown binary file given its structure
Posted on 2003-02-28
I have the structure:
unsigned char userexit1;
unsigned char userexit2;
and I also have a file (a .dat binary file), and I am supposed to write a c file that reads this 5 mb file.
So I tried to create it as something like:
int main( int )
struct ItemRec item;
FILE *file = NULL;
if ( (file = fopen("eamitemr.dat", "r")) != NULL )
while ( !feof( file ) )
int result = fread( &item, sizeof( struct ItemRec ), 1, file );
if ( !result )
cout << item.department << endl;
// I am choosing this field just for example! I'm kinda mixing c and cpp, hope that this isnt much of a problem
fclose ( file );
But no success at all. I just get junk. Am I missing some important point? What should I be looking for?
Thanks in advance for your help.