UNGETC(3) Library Functions Manual UNGETC(3)

ungetcun-get character from input stream

Standard C Library (libc, -lc)

#include <stdio.h>

int
ungetc(int c, FILE *stream);

The () function pushes the character c (converted to an unsigned char) back onto the input stream pointed to by stream. The pushed-back characters will be returned (in reverse order) by subsequent reads on the stream. A successful intervening call to one of the file positioning functions (fseek(3), fsetpos(3), or rewind(3)), using the same stream, will discard the pushed-back characters.

Only one character of push-back is guaranteed, but as long as there is sufficient memory, an effectively infinite amount of push-back is allowed.

If a character is successfully pushed-back, the end-of-file indicator for the stream is cleared. The file-position indicator is decremented by each successful call to (); if its value was 0 before a call, its value is unspecified after the call.

The ungetc() function returns the character pushed-back after the conversion, or EOF if the operation fails. If the value of the argument c character equals EOF, the operation will fail and the stream will remain unchanged.

fseek(3), getc(3), setvbuf(3), ungetwc(3)

The ungetc() function conforms to ISO/IEC 9899:1990 (“ISO C90”).

June 4, 1993 macOS 15.0