unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Page:
Section:
Apropos / Subsearch:
optional field

GETC(3V)                                                              GETC(3V)



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

SYNOPSIS
       #include <&lt;stdio.h>&gt;

       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 invo-
       cation 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.

RETURN VALUES
       On success, getc(), getchar() and fgetc()  return  the  next  character
       from the named input stream as an integer.  On failure, or on EOF, they
       return EOF.  The EOF condition is remembered, even on a  terminal,  and
       all  subsequent  operations  which attempt to read from the stream will
       return EOF until the condition is cleared  with  clearerr()  (see  fer-
       ror(3V)).

       getw()  returns  the next C int from the named input stream on success.
       On failure, or on EOF, it returns EOF, but since EOF is a  valid  inte-
       ger, use ferror(3V) to detect getw() errors.

SYSTEM V RETURN VALUES
       On  failure,  or on EOF, these functions return EOF.  The EOF condition
       is remembered, even on a terminal, however, operations which attempt to
       read  from  the stream will ignore the current state of the EOF indica-
       tion and attempt to read from the file descriptor associated  with  the
       stream.

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

WARNINGS
       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++) does not 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.



                                21 January 1990                       GETC(3V)