|
ungetcfunction
<cstdio> int ungetc ( int character, FILE * stream ); Unget character from stream A character is virtually put back into an input stream at the same position the last character was read and the internal file position indicator is decreased back to that previous position so that this character is returned by the next call to a reading operation on that stream.This character may or may not be the same character as the one last read from the stream in a previous operation. In both cases the value retrieved by the next reading operation on the stream is the one ungot by this function independently of the original character. Notice though, that this only affects the next reading operation on that character, not the content of the physical file associated with the stream, which is not modified by any calls to this function. More than one character can be ungot making them available for reading operations in the reverse order they were put back into the stream. If the End-Of-File internal indicator was set, it is cleared after a call to this function. A call to fseek, fsetpos or rewind on a stream will discard any characters previously put back into it with this function. If the argument passed for the character parameter is EOF, the operation fails and the input stream remains unchanged. Parameters
Return ValueIf successful, the character that was pushed back is returned.On falure, EOF is returned and the stream remains unchanged. Example
This example opens an existing file called myfile.txt for reading and prints its lines, but first gets the first character of every line and puts it back into the stream except if the line begins with #, in which case it is replaced by @. See also
|