/* This has the same results as file4.c, but takes a different approach. Note the use of fclose() to free memory associated to f. */ #include void die_read(void) { fprintf(stderr,"file5: fatal: unable to read data.txt\n"); exit(111); } void printfile(void) { FILE *f; char c; f = fopen("data.txt","r"); if (!f) die_read(); while (fscanf(f,"%c",&c) == 1) putchar(c); if (ferror(f)) die_read(); fclose(f); } int main(void) { printfile(); printfile(); return 0; }