I use fread to read into a char buffer.
char buffer[50];
int nbytes = fread(buffer, 1, 50, fp);
The file I read from contains exactly the word Hello, i.e. 5 bytes.
In the above example, nbytes equals 6. Why?
Additionally, reading from a zero-byte file (i.e. it’s empty) returns 0.
My guess is that whatever wrote to the file you are reading either included a newline (if it’s a text file) or a 0 byte after the string. If you are on unix, run the following command:
Which will print the entire contents of the file including non-printables.
You can also run:
Which will print the length of the file in bytes (along with the filename).