get the next character from a file
#include <stdio.h> int fgetc( FILE *fp );
The fgetc() function gets the next character from the file designated by fp. The character is signed.
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.
#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 ); } }
ANSI
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
errno, fgetchar(), fgets(), fopen(), getc(), getchar(), gets(), ungetc()