ungetc

Undoing the effects of ungetc() : “How” do fseek(),rewind() and fsetpos() do it?Is buffer refilled each time?

混江龙づ霸主 提交于 2019-12-02 12:26:11
问题 Huh!!How shall I put the whole thing in a clear question!!Let me try: I know that the files opened using fopen() are buffered into memory.We use a buffer for efficiency and ease.During a read from the file, the contents of the file are first read to the buffer,and we read from that buffer.Similarly,in a write to the file, the contents are written to the buffer first ,and then to the file. But what with fseek() , fsetpos() and rewind() dropping the effect of the previous calls to ungetc() ?

ungetc: number of bytes of pushback

喜欢而已 提交于 2019-12-01 04:32:18
问题 ungetc is only guaranteed to take one byte of pushback. On the other hand, I've tested it on Windows and Linux and it seems to work with two bytes. Are there any platforms (e.g. any current Unix systems) on which it actually only takes one byte? 回答1: The C99 standard (and the C89 standard before that) said unequivocally: One character of pushback is guaranteed. If the ungetc function is called too many times on the same stream without an intervening read or file positioning operation on that