I've tested the following C code
#include <stdio.h>
int main()
{
FILE * file = fopen("ans.txt", "r+");
printf("%ld", ftell(file)); // prints 0
fgetc(file);
printf("%ld", ftell(file)); // prints -18
printf("%d", fseek(file, 0, SEEK_CUR)); // -1
printf("%ld", ftell(file)); // prints 150
fclose(file);
return 0;
}
on win10 with MinGW-W64 (gcc version 7.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
) and Visual Studio 2017 (cl.exe version Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547
)
The ans.txt
file is (lines end in unix style)
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
line 11
line 12
line 13
line 14
line 15
line 16
line 17
line 18
line 19
line 20
But everything is right on Arch Linux or when I open the file in binary mode or change line ending style into 'Windows/Mac OS 9'.
Is there anything to do with Windows crt?