ferror, feof, clearerr, ungetc

Function Prototype

int ferror(FILE *fp);
int feof(FILE *fp);
void clearerr(FILE *fp);
int ungetc(int c, FILE *fp);

ferror

If buffer I/O stream occur error, then return error flag (non-zero), 0 otherwise

feof

Return non-zero if EOF reached, 0 otherwise

clearerr

  • Clear both error flag and EOF flag for the given file stream
  • Useful when we want continue reading/writing after handling error

ungetc

Function

  • “push back” a character to the input stream
  • The character we push back stored in the buffer
  • The next read operation will receive this pushed-back character first

Remark

  • The character we push back doesn’t have to be the same one we just read
  • No pushing back EOF
  • Clears EOF flag when called