Perhaps it's CRLF? Beware of:
fopen(filename, "r") vs fopen(filename, "rb"),
and likewise
fopen(filename, "w") vs fopen(filename, "wb").
The reason is because "r" or "w" will translate CRLF, while "rb" or "wb" will treat the data as binary. On most platforms this is ignored. For instance, the fopen man page on OS X:
The mode string can also include the
letter "b" either as a third
character or as a character between
the characters in any of the
two-character strings described above.
This is strictly for compatibility
with ISO/IEC 9899:1990 ("ISO C90")
and has no effect; the "b" is
ignored.
The fopen page on MSDN says something different:
b
Open in binary (untranslated) mode;
translations involving carriage-return
and linefeed characters are
suppressed.
If t or b is not given in mode, the
default translation mode is defined by
the global variable _fmode. If t or b
is prefixed to the argument, the
function fails and returns NULL.
For more information about using text
and binary modes in Unicode and
multibyte stream-I/O, see Text and
Binary Mode File I/O and Unicode
Stream I/O in Text and Binary Modes.