Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fopen(3S)

putc(3S)

gets(3S)

ferror(3S)

scanf(3S)

fread(3S)

ungetc(3S)

GETC(3S)  —  STANDARD I/O LIBRARY

NAME

getc, getchar, fgetc, getw − get character or integer from 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 (i.e., 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 C int (word) 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. 

SEE ALSO

fopen(3S), putc(3S), gets(3S), ferror(3S), scanf(3S), fread(3S), ungetc(3S)

DIAGNOSTICS

These functions return the integer constant EOF at end-of-file or upon an error.  The end-of-file condition is remembered, even on a terminal, and all subsequent attempts to read will return EOF until the condition is cleared with clearerr(3S). Because EOF is a valid integer, ferror(3S) should be used to detect getw errors. 

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. 

BUGS

Because it is implemented as a macro, getc treats a stream argument with side effects incorrectly.  In particular, getc(∗f++) doesn’t work sensibly.  Fgetc should be used instead. 

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

Sun Release 3.2  —  Last change: 17 July 1986

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