getc

Gets the next character from a stream.

Library:LibC
Classification:ANSI
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  int getc (
     FILE   *fp);
  

Parameters

fp

(IN) Points to the file.

Return Values

If successful, returns the next byte from the input stream. Otherwise, if the stream is at end-of-file, returns EOF and sets the EOF indicator. If a read error occurs, returns EOF, sets the error indicator, and sets errno to one of the following:

Decimal

Constant

Description

4

EBADF

The file descriptor is not valid for reading.

5

ENOMEM

Insufficient storage space is available.

24

EAGAIN

The O_NONBLOCK flag is set for the file descriptor, and the process cannot immediately perform the read operation.

25

ENXIO

A request was made of a nonexistent device, or the request was outside the capabilities of the device.

28

EIO

The process is orphaned and cannot write to the file.

63

EINTR

A signal interrupted the read operation.

81

EOVERFLOW

The file is a regular file and an attempt was made to read at or beyond the offset maximum associated with the corresponding stream.

Remarks

The getc function or macro gets the next character from the file designated by fp. The character is returned as an int value.

The getc function is equivalent to fgetc, except that it can be implemented as a macro.

See Also