Mega Code Archive

 
Categories / C / Code Snippets
 

Gets a character from the stream

and increments the file position pointer //Header: #include <stdio.h> //Declaration: int fgetc(FILE *stream); //Return: EOF: if the end of the file is reached. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *filep; char ch; if((filep=fopen("testing","r"))==NULL) { printf("Cannot open file.\n"); exit(1); } while((ch=fgetc(filep)) != EOF) { printf("%c", ch); } fclose(filep); return 0; }