Programming Reference/Librarys
Question & Answer
Q&A is closed
int fgetc ( FILE * stream );
Returns next character from (input) stream stream, or EOF on end-of-file or error.
/* * fgetc example code * http://code-reference.com/c/stdio.h/fgetc */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ int main( void ) { FILE *stream; char c; if((stream=fopen("test.txt","r"))==NULL) { printf("Cannot open file.\n"); return 1; } while((c = fgetc(stream) ) != EOF) { printf("%c", c); } fclose(stream); return 0; }
if test.txt exists
output: ./fgetc Line 1 #Line2 Line 3 #Line 4 Line 5
if test.txt not exists
output: ./fgetc Cannot open file.