I would like to use a FILE*
, keep it's current position, make stuff, and compare it's new position to the previous one. Easy.
Eventually, I would like to continue my actions on this FILE*
after an eventual relocation (move back or don't move after doing stuff). Meaning, this FILE*
must continue leaving properly.
Example:
fpos_t originalPos, preBOM;
fgetpos(inFile, &originalPos);
rewind(inFile);
fgetpos(inFile, &preBOM);
unsigned char firstChar = fgetc(inFile); // Some readings...
if (originalPos != preBOM) /* Problematic comparison*/
fsetpos(inFile, &originalPos);
Because of some advices (below), I put me in mind to use fgetpos
instead of ftell
. Maybe it's a mistake?
Mention to the fgetpos
/vs/ ftell
question: what is difference between fgetpos/fsetpos and ftell/fseek
The problem is I want to compare 2 "positions" which are in fact states (non trivial types) and have no comparison operator. And are not implemented the same on different compilers.
How can I compare originalPos
to preBOM
?
Quote from
The content of an fpos_t object is not meant to be read directly, but only to be used as an argument in a call to fsetpos.
That means, you can't compare fpos_t
's.