Here's a suggestion: whenever you get a result you don't understand, use printf() to troubleshoot.
For example, use something like
Code:
printf("Debug: inChar = <%02X>\n", inChar);
after the line that reads a byte from the file.
If this doesn't tell you something (that is, if you don't understand,
what it tells you) get back to us.
printf() is your friend.
Regards,
Dave