Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ungetc - Push back a character to the buffer

&pagelevel(4)&pagelevel

Definition   

#include <stdio.h>

int ungetc(int c, FILE *fp);

ungetc pushes the character c back to the buffer assigned to the file described by file pointer fp. The next read operation that reads one character at a time from this file (getc) will then return c once again.
If c is equal to EOF, ungetc has no effect, and EOF is returned.

Return val.

The pushed back character c


if successful.

EOF

if ungetc cannot push back the character (due to an error or if c is EOF).

Notes

At least one character must always have been read from the file before the first ungetc call.

EOF cannot be pushed back.

After a successful ungetc call, the read/write pointer is moved back one character.

A call to one of the following functions cancels the effects of the ungetc call (e.g. backward positioning): fseek/fseek64, fsetpos/fsetpos64, lseek/lseek64, rewind, fflush.

If a character other than the one read previously is returned to the buffer, the result differs depending on whether KR or ANSI functionality is being used.
With KR functionality (applies to C/C++ versions prior to V3.0 only) the original data is changed when the buffer contents are written to the external file.
With ANSI functionality the original data is not changed when the buffer contents are written to the external file, i.e. the original data prior to the ungetc call is always written into the external file.

See also

getc, ungetwc