FAT | RFS | XFS | ZFS

fgetc()

PROTOTYPE

#include <stdio.h>

int fgetc(FILE *file);

DESCRIPTION

fgetc() attempts to read one byte from the open regular file identified by file. If the file is at its end, the end-of-file indicator is set. If the end-of-file indicator is set, fgetc() returns EOF. If an error occurs, errno and the file’s error indicator are set, and fgetc() returns EOF.

Otherwise, one byte is read from the file’s current position. The file position, if defined, is advanced by one. fgetc() returns the byte as an “unsigned char” converted to “int”.

Unless disabled via FSF_NOATIME or only a byte pushed back by ungetc() is read, the file’s data access timestamp is updated.

ERROR CODES

EBADF file is not the handle of a file open in read mode.
EISDIR file refers to a directory.

EXAMPLE

/*-------------------------------------------------------------*/
/* Open the file and write it to stdout.                       */
/*-------------------------------------------------------------*/
file = fopen("/flash/temp.txt", "r");
while (feof(file) == 0)
  putchar(fgetc(file));