I'm writing a program to read some information (irrelevant for this question) from a file. To reach this information, I have used quite a few
fseek()
's, since there's a lot of stuff between the beginning of the file and what I want. However, the information being searched for is manually inputted by the user, so typo's are possible.
I am aware of
rewind()
, but would like to, instead, have a pointer stay at the beginning of the potentially-relevant section of the file while another pointer runs through the file itself. That way, should there have been a typo, the moving pointer can simply return to the value of the initial pointer.
However, should I do
1 2 3
|
FILE* mem = f; //f has already been assigned the open file
/*lots of fseek()'s*/
f=mem;
|
It doesn't work. Following the steps, I can see that even though all the
fseek()
's are only applied to f, the contents of mem also move. I have also tried using
const FILE* mem=f
, but the mem pointer still moves. I have also tried
FILE* mem = *f
and
FILE* mem = &f
, which didn't work for obvious reasons.
How can I make mem's values not change while f's do?