UNGETC(3S) UNGETC(3S) NAME ungetc - push character back into input stream SYNOPSIS #include <stdio.h> int ungetc (int c, FILE *stream); DESCRIPTION ungetc inserts the character c into the buffer associated with an input stream. Pushed-back characters will be returned by subsequent reads on that stream in the reverse order of their pushing. A successful intervening call (with the stream pointed to by stream) to a file positioning function (fseek(3S), fsetpos(3S) or rewind(3S)), discards any pushed-back characters. The external storage corresponding to the stream is unchanged. A successful call to ungetc clears the end-of-file indicator for the stream. One character of pushback is guaranteed, provided something has already been read from the stream and the stream is actually buffered. If c equals EOF, the operation fails and the input stream is unchanged. SEE ALSO fseek(3S), fsetpos(3S), getc(3S), rewind(3S), setbuf(3S), stdio(3S). DIAGNOSTICS ungetc returns the character pushed back, or EOF if it cannot insert the character. BUGS When stream is stdin, one character may be pushed back onto the buffer without a previous read statement. An ungetc on an unbuffered stream (including stderr) may succeed, with the following consequences. If the stream is open for input, the pushed-back character will be prepended to the input. If the stream is open only for output, the next character written to the output stream may be lost. Page 1