If it's a binary file (seems likely if you're using a hex dump to read it), then you need to use fwrite (or fputc), and probably use "wb" mode as well (especially if you're on windows).
You shouldn't try to write a struct, unless you know for sure that you have all the padding and alignment issues sorted out (this isn't easy, or portable).
Even if you have say
Code:
unsigned short width;
fwrite(&width,sizeof(width),1,fp);
can have problems with endian
The only truly safe and portable way is something like
Code:
fputc( width & 0xFF, fp ); // The LSB
fputc( ( width >> 8 ) & 0xff, fp ); // The MSB
Google "padding and alignment" and "endian".