Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

gets(3)

getwc(3)

putc(3)

unlocked_getc(3)

unlocked_getchar(3)

getc(3)  —  Subroutines

OSF

NAME

getc, fgetc, getchar, getw - Gets a character or word from an input stream

LIBRARY

Standard I/O Package (libc.a)

SYNOPSIS

#include <stdio.h>

int getc (
FILE ∗stream );

int fgetc (
FILE ∗stream );

int getchar ( void );

int getw (
FILE ∗stream );

PARAMETERS

streamPoints to the file structure of an open file. 

DESCRIPTION

The getc() macro returns the next byte from the input specified by the stream parameter and moves the file pointer, if defined, ahead one byte in stream. The getc() macro cannot be used where a function is necessary; for example, a subroutine pointer cannot point to it. 

Because it is implemented as a macro, getc() does not work correctly with a stream parameter that has side effects.  In particular, the following does not work:

getc(∗f++)

In cases like this, use the fgetc() function instead. 

The fgetc() function performs the same function as the getc() macro, but fgetc() is a subroutine, not a macro. 

The getchar() macro returns the next byte from stdin, the standard input stream. Note that getchar() is also a macro. 

The getw() function returns the next word (int) from the input specified by the stream parameter and increments the associated file pointer, if defined, to point to the next word.  The size of a word varies from one machine architecture to another.  The getw() function returns the constant EOF at the end of the file or when an error occurs. Since EOF is a valid integer value, the feof() and ferror() functions can be used to check the success of getw(). The getw() function assumes no special alignment in the file. 

Because of possible differences in word length and byte ordering from one machine architecture to another, files written using the putw() subroutine are machine dependent and may not be readable using getw() on a different type of processor. 

NOTES

The reentrant versions of these functions are all locked against multiple threads calling them simultaneously.  This will incur an overhead to ensure integrity of the stream.  The unlocked versions of these calls may be used safely, providing that the stream is locked when the calls are used, using the flockfile() and funlockfile() functions. 

AES Support Level:
Full use (getc(), fgetc(), getchar())
Trial use (getw())

RETURN VALUES

These functions and macros return the integer constant EOF at the end of the file or upon an error. 

RELATED INFORMATION

Functions: gets(3), getwc(3), putc(3), unlocked_getc(3), unlocked_getchar(3)

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