[Previous]
[Contents]
[Next]

getc()

get the next character from a file

Synopsis:

#include <stdio.h>
int getc( FILE *fp );

Description:

The getc() function gets the next character from the file designated by fp. The character is returned as an int value. The getc() function is equivalent to fgetc(), except that it may be implemented as a macro.

Returns:

The next character from the input stream pointed to by fp. If the stream is at end-of-file, the end-of-file indicator is set, and getc() returns EOF. If a read error occurs, errno is set, and getc() returns EOF.

Examples:

#include <stdio.h>

void main()
  {
    FILE *fp;
    int c;

    fp = fopen( "file", "r" );
    if( fp != NULL ) {
      while( (c = getc( fp )) != EOF )
        putchar(c);
      fclose( fp );
    }
  }

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

getc() may be implemented as a macro.

See also:

errno, fgetc(), fgetchar(), fgets(), fopen(), getchar(), gets(), ungetc()


[Previous]
[Contents]
[Next]