I'm writing an array of 3 integers to a file using C's fwrite function but when opening the output file with gedit (using Unicode UTF-8), I get the following error:
There was a problem opening the file. The file you opened has invalid characters. If you continue editing this file, you could corrupt the document.
Here's the relevant code snippet:
char* imageFile = "image.txt";
FILE* imageFilePtr = fopen(imageFile, "w");
int scores[3] = {69, 70, 71};
fwrite(scores, sizeof(int), sizeof(scores), imageFilePtr);
When I use a hexadecimal reader such as "xxd", I get the following in my terminal:
0000000: 4500 0000 4600 0000 4700 0000 7031 7108 E...F...G...p1q.
0000010: 0830 7108 2987 0408 2087 0408 0460 cebf .0q.)... ....`..
0000020: 0100 0000 0000 0000 0000 0000 0000 0000 ................
Keep in mind that the in my environment, sizeof(int) is 4 bytes. Thus, I can see how 69, 70, and 71 in decimal are being printed to the file as 45, 46, and 47 in hex as xxd shows. But, where are all the other bytes after "4700 0000" coming from? And, why can't I open the output file, "image.txt", with a text editor to see a file that shows the decimal numbers, 69, 70, and 71 written inside?