When I use SEEK_END
, I expect it to correspond to the position of the last character in the stream. But inside a printf it seems like it does not.
I have a file that contains 1010 characters. I open it with fopen
, then I try to print the position of the last character of this file:
printf("Last position is: %d\n", SEEK_END);
The output is Last position is: 2
whereas I expect it to be Last position is: 1010
. 2
does not correspond to the last line or last column, since I have 101 lines of 10 characters each. I don't know what it is.
Curiously, this code works well:
fseek(file, 0, SEEK_END);
printf("Last position is: %d\n", ftell(file));
The output is Last position is: 1010
. But the problem here is that I am moving the virtual cursor in the file, which I do not want.
How can I print the value of SEEK_END
without having to change the position of the virtual cursor, and more importantly, why do my printf
outputs 2
?