Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fclose(3S)

ferror(3S)

fopen(3S)

fread(3S)

gets(3S)

putc(3S)

scanf(3S)

stdio(3S)

GETC(3S)                             SysV                             GETC(3S)



NAME
     getc, getchar, fgetc, getw - get character or word from a stream

SYNOPSIS
     #include <stdio.h>

     int getc (stream)
     FILE *stream;

     int getchar ()

     int fgetc (stream)
     FILE *stream;

     int getw (stream)
     FILE *stream;

DESCRIPTION
     getc returns the next character (that is, byte) from the named input
     stream, as an integer.  It also moves the file pointer, if defined, ahead
     one character in stream.  getchar is defined as getc(stdin).  getc and
     getchar are macros.

     fgetc behaves like getc, but is a function rather than a macro.  fgetc
     runs more slowly than getc, but it takes less space per invocation and
     its name can be passed as an argument to a function.

     getw returns the next word (that is, integer) from the named input
     stream.  getw increments the associated file pointer, if defined, to
     point to the next word.  The size of a word is the size of an integer and
     varies from machine to machine.  getw assumes no special alignment in the
     file.

DIAGNOSTICS
     These functions return the constant EOF at end-of-file or upon an error.
     Because EOF is a valid integer, ferror(3S) should be used to detect getw
     errors.

ERRORS
     The getc, getw, getchar, and fgetc functions fail if either the stream is
     unbuffered, or the stream's buffer needed to be flushed and the function
     call caused an underlying read or lseek to be invoked. In addition, the
     getc, getw, getchar, or fgetc fail if

     [EAGAIN]       The O_NONBLOCK flag is set for the file descriptor
                    underlying stream and the process would be delayed in the
                    read operation.

     [EBADF]        The file descriptor underlying stream is not a valid file
                    descriptor open for reading.

     [EINTR]        The read operation was interrupted by a signal which was
                    caught, and no data was transferred.

     [EIO]          The implementation supports job control, the process is a
                    member of a background process group attempting to read to
                    its controlling terminal, TOSTOP is set, the process is
                    neither ignoring nor blocking SIGTTOU and the process
                    group of the process is orphaned.

SEE ALSO
     fclose(3S), ferror(3S), fopen(3S), fread(3S), gets(3S), putc(3S),
     scanf(3S), stdio(3S).

WARNING
     If the integer value returned by getc, getchar, or fgetc is stored into a
     character variable and then compared against the integer constant EOF,
     the comparison may never succeed, because sign-extension of a character
     on widening to integer is machine-dependent.

CAVEATS
     Because it is implemented as a macro, getc evaluates a stream argument
     more than once.  In particular, getc(*f++) does not work sensibly.  fgetc
     should be used instead.

     Because of possible differences in word length and byte ordering, files
     written using getw are machine-dependent, and may not be read using getw
     on a different processor.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026