I'm trying to read a binary file with fread() function.
I want to read 2 byte every time (UTF-16 file).
The relative code:
char words[2];
while(fread(&words, sizeof(words), 1, sFile))
//do somthing...
The information from the file is stored only in the first place of the array, and the second stay as zero. Any idea? Thanks
freadreturns? What doesfwrite(which I assume you use to write) return? Please try to create a Minimal, Complete, and Verifiable Example showing both writing and reading.char words[2] = {0xaa};and see if you observe change from0xaato some other value.0x20..0x7Eand the other containing0x00. Assuming you're using Intel hardware, you have little-endian encoding, so the first byte might be 0x41 (Ain ISO 8859-1) and the second would be 0x00.char words[2] = {0xaa, 0x55};and set both to non-zero.