Mega Code Archive

 
Categories / C / Code Snippets
 

Determines whether the end of the file has been reached

//Declaration: int feof(FILE *stream); //Return: A nonzero value: if the file pointer is at the end of the file. zero: otherwise. #include <stdio.h> #include <stdlib.h> int main(void){ FILE *filep; if((filep=fopen("testing", "rb"))==NULL) { printf("Cannot open file.\n"); exit(1); } while(!feof(filep)) { char ch = getc(filep); printf("%c",ch); } fclose(filep); }