UNGETC - push character back into input stream.

(ANSI Standard)


#include <stdio.h>
ret = ungetc( c, fp );


int c;
is the character to be pushed back.
FILE *fp;
is the input file that gets the character back.
int ret;
is the character that was pushed back. If the pushback operation is unsuccessful for some reason (e.g. the file is not open), EOF is returned.


"ungetc" pushes a character back into an input stream. The next "getc" to that stream will return the character that was pushed back.

You can only push back characters into a stream if something has already been read from that stream and if the input from the stream is buffered. Trying to push back several characters in succession may or may not work; it will be highly machine dependent. You cannot push back more than three characters at a time with NS mode C.

"ungetc" will not attempt to push back the EOF character.

A side effect of the "fseek" function is that all memory of pushed back characters is lost.

See Also:

expl nsc lib fseek

expl nsc lib getc

Copyright © 1996, Thinkage Ltd.