Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fclose(3)

ferror(3)

fopen(3)

fread(3)

gets(3)

putc(3)

scanf(3)

stdio(3)



  getc(3)                             CLIX                             getc(3)



  NAME

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

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <stdio.h>

    int getc(
      FILE *stream );

    int getchar(
      void );

    int fgetc(
      FILE *stream );

    int getw(
      FILE *stream );

  PARAMETERS

    stream   Specifies an input stream.

  DESCRIPTION

    The getc() macro 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.  The getchar() macro is defined as
    getc(stdin).

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

    The getw() function returns the next word (that is, integer) from the
    named input stream.  The getw() function 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.  The getw()
    function assumes no special alignment in the file.

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

    Because of possible differences in word length and byte ordering, files



  2/94 - Intergraph Corporation                                              1






  getc(3)                             CLIX                             getc(3)



    written using putw() are machine-dependent, and may not be read using
    getw() on a different processor.

  EXAMPLES

    To copy a file:

    FILE *infile;
    FILE *outfile;
    int letter;

    infile = fopen(argv[1], "r");
    outfile = fopen(argv[2], "w");

    while ((letter = getc(infile)) != EOF)
         putc(letter, outfile);


  CAUTIONS

    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.

  RETURN VALUES

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

  RELATED INFORMATION

    Functions:  fclose(3), ferror(3), fopen(3), fread(3), gets(3), putc(3),
    scanf(3), stdio(3)



















  2                                              Intergraph Corporation - 2/94




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