Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fgetc(3S) — HP-UX 7.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fclose(3S)

ferror(3S)

fopen(3S)

fread(3S)

gets(3S)

putc(3S)

scanf(3S)

GETC(3S)

NAME

getc, getchar, fgetc, getw − get character or word from a stream file

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 unsigned character converted to 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 defined as both macros and functions. 

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 (i.e.  int in C) 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

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

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. 

WARNING

The getc and getchar routines are implemented as both library functions and macros.  The macro versions, which are used by default, are defined in <stdio.h>.  To obtain the library function either use a #undef to remove the macro definition or, if compiling in ANSI-C mode, enclose the function name in parenthesis or use the function address.  For following example illustrates each of these methods :

#include <stdio.h>
#undef getc
... 
main()
{
int (*get_char()) ();
... 
return_val=getc(c,fd);
... 
return_val=(getc)(c,fd1);
... 
get_char = getchar;
};

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. 

The macro version of getc incorrectly treats a stream argument with side effects.  In particular, getc(∗f++) does not work sensibly.  The function version of getc or 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 read using getw on a different processor. 

STANDARDS CONFORMANCE

getc: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1, ANSI C

fgetc: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1, ANSI C

getchar: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1, ANSI C

getw: SVID2, XPG2, XPG3

Hewlett-Packard Company  —  HP-UX Release 7.0: Sept 1989

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