ungetc(3S)
NAME
ungetc(), ungetc_unlocked() − push character back into input stream
SYNOPSIS
#include <stdio.h>
int ungetc(int c, FILE *stream);
int ungetc_unlocked(int c, FILE *stream);
DESCRIPTION
ungetc() inserts the character c (converted to an unsigned char) into the buffer associated with an input stream. That character, c, is returned by the next call to getc() (see getc(3S)) on that stream. A successful intervening call to a file positioning function with stream (fseek(), fsetpos(), or rewind()) erases all memory of the inserted characters.
ungetc() affects only the buffer associated with the input stream. It does not affect the contents of the file corresponding to stream.
One character of pushback is guaranteed.
If c equals EOF, ungetc() does nothing to the buffer and returns EOF.
ungetc_unlocked() is identical to ungetc() except it does not perform any internal locking of the stream for multi-thread applications. ungetc_unlocked() can be used by multi-thread applications which have already used flockfile() to acquire a mutual exclusion lock for the stream (see flockfile(3S)).
RETURN VALUE
If successful, ungetc() and ungetc_unlocked() return c and clear the end-of-file indicator for the stream. ungetc() and ungetc_unlocked() return EOF if they cannot insert the character.
SEE ALSO
flockfile(3S), fseek(3S), fsetpos(3S), getc(3S), setbuf(3S).
STANDARDS CONFORMANCE
ungetc(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C
Hewlett-Packard Company — HP-UX Release 10.20: July 1996