Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

FGETC

Portability Function: Reads the next available character from a file specified by a Fortran unit number.

Module

USE IFPORT

result = FGETC (lunit,char)

lunit

(Input) INTEGER(4). Unit number of a file. Must be currently connected to a file when the function is called.

char

(Output) CHARACTER*1. Next available character in the file. If lunit is connected to a console device, then no characters are returned until the Enter key is pressed.

Results

The result type is INTEGER(4). The result is zero if the read is successful, or -1 if an end-of-file is detected. A positive value is either a system error code or a Fortran I/O error code, such as:

EINVAL: The specified unit is invalid (either not already open, or an invalid unit number).

If you use WRITE, READ, or any other Fortran I/O statements with lunit, be sure to read Portability Routines.

Example

USE IFPORT
CHARACTER inchar
INTEGER istatus
istatus = FGETC(5,inchar)
PRINT *, inchar
END

See Also