| Wiki Markup |
|---|
Section 7.19.7.11 of C99 defines {{ungetc()}} as follows: \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] |
The
ungetcfunction pushes the character specified byc(converted to anunsigned char) back onto the input stream pointed to bystream. 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 bystream) to a file positioning function (fseek,fsetpos, orrewind) discards any pushed-back characters for the stream. The external storage corresponding to the stream is unchanged.One character of pushback is guaranteed.
The ungetc() function pushes a character onto an input stream. This pushed character can then be read by subsequent calls to functions that read from that stream. However, the ungetc() function has serious limitations. A call to a file positioning function, such as fseek(), will discard any character pushed back by ungetc(). Also, the C standard only guarantees that the pushing back of one character will succeed. Consequently, subsequent calls to ungetc() must be separated by a call to a read function or a file-positioning function (which will discard any data pushed by ungetc()).
...