char hd_makefile(char* fname)
{
FILE* desc = fopen(fname, "w+b");
if (desc == NULL) {
perror("hd_makefile: error while creating the file.\n");
return -1;
}
hd_fileheader head = { HD_MAGICNUMBER, HD_VERSION, 1 };
// Write the header to file.
if (fwrite(&head, sizeof(hd_fileheader), 1, desc) != 1) {
perror("hd_makefile: error while writing the header.\n");
return -1;
}
fflush(desc);
return 0;
}
The problem is that the output file (viewed with GHex2 is 20 bytes long althrough i'm using (8 * 2 + 2) bytes = 18 bytes.
Here is the hex view: 41 54 41 44 48 00 00 00 01 00 6C B7 01 00 00 00 00 00 00 00
As you can see the bytes of the MAGICNUMBER are inverted. I also cannot understand where does the 6C B7 comes from...
Thank you.