sean-keys
asked on
Best way to rewind a file stream one character in c not c++
Hi
I have some C code where I have a
char myChar = fgetc(file);
What I want to do next is "rewind" two characters back so the next time i call fgetc(file) it will give me the character that came before my
char myChar = fgetc(file);
Thanks,
Sean
I have some C code where I have a
char myChar = fgetc(file);
What I want to do next is "rewind" two characters back so the next time i call fgetc(file) it will give me the character that came before my
char myChar = fgetc(file);
Thanks,
Sean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But pushing characters back on a stream will alter the stream contents correct? What if the stream is read-only?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can only "rewind" a stream if it is seekable. Some streams aren't seekable, so you would have to use ungetc() to actually push characters back onto the stream.