I am having a problem where ftell is returning an incorrect value. My code, when run in netbeans on linux reports correctly, but the exact same code, running in netbeans on windows (using mingw) reports incorrectly. the file pointer is to a file opened in BINARY_READ. in my linux netbeans, after running my subroutine, the ftell reports 35. in my windows netbeans, the after calling the same subroutine, the ftell is 3621. I traced through my subroutine and the following statement appears to cause the problem:
if (((header_size = getc (fp)) == EOF) || (header_size == 0))
on my linux netbeans, the ftell(fp) after this statement results in 1. but on my windows netbeans, the ftell(fp) after this statement is 3585.
what could be causing the problem?
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.