FAT | RFS | XFS | ZFS
ungetc()
PROTOTYPE
#include <stdio.h>
int ungetc(int ch, FILE *file);
DESCRIPTION
ungetc() pushes one byte back to the file specified by file, so it is read by the next input operation. ch is converted to “unsigned char” and virtually stored on the file. No non-volatile storage is changed. Attempts to push back EOF have no effect.
ungetc() fails if a byte has already been pushed-back when it is called. The pushed-back byte is read and removed by any API routine that performs input. It is also removed by: fflush(), fseek(), fsetpos(), lseek(), and rewind().
Input operations that only read a pushed-back byte do not update the file’s data access timestamp.
If successful, ungetc() clears the end-of-file indicator and returns ch. Otherwise, it returns EOF.
ERROR CODES
| EBADF | file is not the handle of an open file. |
| EISDIR | file refers to a directory. |
EXAMPLE
file = fopen("/flash/log.txt", "r");
/*-------------------------------------------------------------*/
/* Output the first letter in "log.txt" 12 times. */
/*-------------------------------------------------------------*/
for (i = 0; i < 12; ++i)
{
ch = getc(file);
printf("%c", ch);
ungetc(ch, file);
}