FAT | RFS | XFS | ZFS

getc()

PROTOTYPE

#include <stdio.h>

int getc(FILE *file);

DESCRIPTION

getc() 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, getc() returns EOF. If an error occurs, it sets errno and the file’s error indicator, and returns EOF.

Otherwise, one byte is read from the file’s current position. The file position, if defined, is advanced by one. getc() 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.

getc() is identical to fgetc() except that getc() may be implemented as a macro.

ERROR CODES

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

EXAMPLE

/*-------------------------------------------------------------*/
/* Open file and copy it to stdout.                            */
/*-------------------------------------------------------------*/
file = fopen("/flash/temp.txt", "r");
while (feof(file) == 0)
  printf("%c", getc(file));