Link to home
Start Free TrialLog in
Avatar of sean-keys
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
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It depends on the type of file, also.

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.
Avatar of sean-keys
sean-keys

ASKER

But pushing characters back on a stream will alter the stream contents correct?  What if the stream is read-only?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial