You need to open the file in binary mode:
fp = fopen(name, "rb");
or similar. You should get in a habit of always doing this, since only binary mode has well-defined behavior in standard C. On POSIX systems, binary and text (default) mode behave the same, but on windows, munging of newlines takes place in a way that messes up file contents and offsets.