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
can have problems with endian
unsigned short width;
The only truly safe and portable way is something like
Google "padding and alignment" and "endian".
fputc( width & 0xFF, fp ); // The LSB
fputc( ( width >> 8 ) & 0xff, fp ); // The MSB