Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
ungetc
◄Summary► ◄Example► ◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
The ungetc function pushes the character <c> back onto <stream>
and clears the end-of-file indicator. The stream must be open for
reading. A subsequent read operation on the stream starts with
<c>. An attempt to push EOF onto the stream using ungetc is
ignored. The ungetc function returns an error value if nothing has
yet been read from <stream>, or if <c> cannot be pushed back.
Characters placed on the stream by ungetc may be erased if fflush,
fseek, fsetpos, or rewind is called before the character is read
from the stream. The file-position indicator will have the same
value it had before the characters were pushed back.
On a successful ungetc call against a text stream, the file-
position indicator is unspecified until all the pushed-back
characters are read or discarded. On each successful ungetc call
against a binary stream, the file-position indicator is stepped
down. If its value was 0 before a call, the value is undefined
after the call.
Results are unpredictable if the ungetc function is called twice
without a read operation between the two calls. After a call to
the fscanf function, a call to ungetc may fail unless another
read operation (such as the getc function) has been performed.
This is because the fscanf function itself calls the ungetc
function.
Return Value
The ungetc function returns the character argument <c>. The return
value EOF indicates a failure to push back the specified character.
-♦-