Reading from files

You can use the following library functions to read in information from terminal files; see z/OS XL C/C++ Runtime Library Reference for more information on these library functions.
  • fread()
  • fread_unlocked()
  • fgets()
  • fgets_unlocked()
  • gets()
  • gets_unlocked()
  • fgetc()
  • fgetc_unlocked()
  • getc()
  • getc_unlocked()
  • getchar()
  • getchar_unlocked()
  • scanf()
  • scanf_unlocked()
  • fscanf()
  • fscanf_unlocked()
  • vscanf()
  • vscanf_unlocked()
  • vfscanf()
  • vfscanf_unlocked()

You can set up a SIGIOERR handler to catch read or write system errors. See Debugging I/O programs for more information.

A call to the rewind() function clears unread input data in the terminal buffer so that on the next read request, the system waits for more user input.

With z/OS® Language Environment®, an empty record is considered EOF in binary mode or record mode. This remains in effect until a rewind() or clearerr() is issued. When the rewind() is issued, the buffer is cleared and reading can continue.

Under TSO, the virtual line size of the terminal is used to determine the line length.

When reading from the terminal and the RECFM has been set to be F (for example, by an ALLOCATE under TSO) in binary or record mode, the input is padded with blanks to the record length.

On input, all terminal files opened for output flush their output, no matter what type of file they are and whether a record is complete or not. This includes fixed terminal files that would normally withhold output until a record is completed, as well as text records that normally wait until a new-line or carriage return. In all cases, the data is placed into one line with a blank added to separate output from different terminal files. Fixed terminal files do not pad the output with blanks when flushing this way.

Note: This flush is not the same as a call to fflush(), because fixed terminal files do not have incomplete records and text terminal files do not output until the new-line or carriage return. This flush occurs only when actual input is required from the terminal. When data is still in the buffer, that data is read without flushing output terminal files.