0

Is there a way we can decrement a file pointer. I searched online and I found the ungetc() function but what if we want to decrement the file pointer to point to the last string in the database? Also, how does ungetc put back a character?? Explain. Thanks in advance!!

3
Contributors
2
Replies
24
Views
4 Years
Discussion Span
Last Post by deceptikon
0

Check out fseek() to smartly maneuver around a file. Any time the records of the database are not fixed in their size, (that is, all the same size), you will find it more difficult finding your way around inside a file.

Conceptually, there is a tiny buffer, than can be used with ungetc(). Nothing is actually "put back" into the input stream, it's just put into the buffer, and a flag tells the next access to check that tiny buffer first. The actual implementation is left up to the compiler maker.

This is not a factual understanding, but my understanding of it. I'm sure you could Google and get better info.

0

Check out fseek() to smartly maneuver around a file.

Note that arbitrary seeking on a stream opened in text mode is technically undefined. To use anything except an offset of 0 or the result of a previous ftell() call, the stream must be opened in binary mode.

Also, how does ungetc put back a character?? Explain.

If you're feeling adventurous enough to look at an actual implementation (it's written with clarity in mind), check out these links:

FILE structure
ungetc
fgetc

You'll see that a separate unget buffer is used to hold pushed back characters, where the buffer takes priority over the primary character buffer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.