I'm learning about C File I/O and writing my first test programs and I'm curious about something. Here is a function that write 2 byte signed integers to a file:
void writexyz(FILE* output, signed short x, signed short y, signed short z)
fwrite(&x, 2, 1, output);
fwrite(&y, 2, 1, output);
fwrite(&z, 2, 1, output);
And here is how it's called from my "main":
But when I look the file, expecting to see 0x1F40, 0x0000 and 0xE0C0 the numbers are swapped: 0x1F40 becomes 0x401F and so on. Why is this? And how I can access bytes of my signed shorts so I can swap them? I know how to do this in an array but I'm not sure what's the method for an integer.
signed short x1, y1, z1;
x1 = 8000;
y1 = 0;
z1 = -8000;
writexyz(output_file, x1, y1, z1);
Sorry if my questions are too basic, I'm learning C myself for fun and I'm still confused about a lot of basic things.