ungetc(3S) ungetc(3S)
NAME
ungetc, ungetwc - push character back onto input stream
SYNOPSIS
#include <stdio.h>
int ungetc(int c, FILE *stream);
cc [flag ...] file ... -lw [library ...]
#include <stdio.h>
#include <wchar.h>
wintt ungetwc(wintt wc, FILE *stream);
DESCRIPTION
ungetc() pushes back the character specified by c (converted to an
unsigned char) into the buffer associated with the input stream
pointed to by stream.
ungetwc() pushes back a wide character wc in the buffer. These charac-
ters are then returned again by the next getc(3S) or getwc(3S) call
for stream. ungetc() returns c; ungetwc() returns wc; the file associ-
ated with stream remains unchanged.
A successful call to ungetc() or ungetwc() clears the EOF indicator of
the input stream.
For ungetc() storage space is guaranteed for a pushed-back character,
for ungetwc() a returned wide character is guaranteed.
The value of the file position indicator for stream after reading or
discarding all pushed-back bytes will be the same as it was before the
bytes were pushed back. The file position indicator is decremented by
each successful call to ungetc(). If its value was zero before a call,
its value is indeterminate after the call.
If c equals EOF, ungetc() does nothing to the buffer and returns EOF.
If the value of wc equals that of the macro WEOF, no wide character is
pushed back to the buffer.
fseek() and rewind() [both described under fseek(3S)], and setpos()
erase the memory of inserted characters for the stream on which they
are applied.
If ungetc() or ungetwc() is called too many times on the same stream
without an intervening read or file-positioning operation, the func-
tion will fail.
Page 1 Reliant UNIX 5.44 Printed 11/98
ungetc(3S) ungetc(3S)
RESULT
ungetc() returns EOF if it cannot push back the character.
ungetwc() returns WEOF if it cannot push back the wide character.
If the characters are pushed back, the characters themselves are
returned after conversion.
SEE ALSO
read(2), fsetpos(3C), fgetwc(3S), fseek(3S), getc(3S), rewind(3S),
setbuf(3S), stdio(3S), wchar(5).
Page 2 Reliant UNIX 5.44 Printed 11/98