FAT | RFS | XFS | ZFS
getchar()
PROTOTYPE
#include <stdio.h>
int getchar(void);
DESCRIPTION
getchar() attempts to read one byte from the open regular file identified by stdin. If the file is at its end, the end-of-file indicator is set. If the end-of-file indicator is set, getchar() 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. getchar() 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 | stdin is not the handle of a file open in read mode. |
| EISDIR | stdin refers to a directory. |
EXAMPLE
/*-------------------------------------------------------------*/
/* Echo stdin to stdout until 'q' is entered. */
/*-------------------------------------------------------------*/
do
{
ch = getchar();
if (ch == EOF)
perror("error reading from input");
putchar(ch);
} while (ch != 'q');