The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

ungetc - push byte back into input stream

 SYNOPSIS



#include <stdio.h>

int ungetc(int c, FILE *stream);

 DESCRIPTION

The ungetc() function pushes the byte specified by c (converted to an unsigned char) back onto the input stream pointed to by stream. The pushed-back bytes 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 (.Fn fseek , fsetpos() or rewind()) discards any pushed-back bytes for the stream. The external storage corresponding to the stream is unchanged.

One byte of push-back is guaranteed. If ungetc() is called too many times on the same stream without an intervening read or file-positioning operation on that stream, the operation may fail.

If the value of c equals that of the macro EOF, the operation fails and the input stream is unchanged.

A successful call to ungetc() clears the end-of-file indicator for the stream. The value of the file-position indicator for the 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 0 before a call, its value is indeterminate after the call.

 RETURN VALUE

Upon successful completion, ungetc() returns the byte pushed back after conversion. Otherwise it returns EOF.

 ERRORS

No errors are defined.

 EXAMPLES

None.

 APPLICATION USAGE

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

fseek(), getc(), fsetpos(), read(), rewind(), setbuf(), <stdio.h>.

DERIVATION

Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]