Reading from files
You can use the following library functions to read from a file:
- fread()
- fread_unlocked()
- fgetc()
- fgetc_unlocked()
- fgets()
- fgets_unlocked()
- fscanf()
- fscanf_unlocked()
- getc()
- getc_unlocked()
- gets()
- gets_unlocked()
- getchar()
- getchar_unlocked()
- scanf()
- scanf_unlocked()
- vfscanf()
- vfscanf_unlocked()
- vscanf()
- vscanf_unlocked()
fread() is the only interface allowed for reading
record I/O or blocked I/O files. Except for blocked I/O files, a read
operation directly after a write operation without an intervening
call to fflush(), fsetpos(), fseek(), or rewind() fails. z/OS® XL
C/C++ treats the following as read operations:
- Calls to read functions that request 0 bytes
- Read requests that fail because of a system error
- Calls to the ungetc() function
z/OS XL C/C++ does not consider a read to be at EOF until you try to read past the last byte visible in the file. For example, in a file containing three bytes, the feof() function returns FALSE after three calls to fgetc(). Calling fgetc() one more time causes feof() to return TRUE.
You can set up a SIGIOERR handler to catch read or write system errors. See the debugging section in this information for more details.