[Previous]
[Contents]
[Next]

fgetc()

get the next character from a file

Synopsis:

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

Description:

The fgetc() function gets the next character from the file designated by fp. The character is signed.

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 fgetc() returns EOF. If a read error occurs, the error indicator is set, and fgetc() returns EOF.

When an error occurs, the global variable errno contains a value indicating the type of error that has been detected.

Examples:

#include <stdio.h>

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

    fp = fopen( "file", "r" );
    if( fp != NULL ) {
      while( (c = fgetc( fp )) != EOF )
        fputc( c, stdout );
      fclose( fp );
    }
  }

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

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


[Previous]
[Contents]
[Next]