/* file2.c Author: James Tam Version: January 10, 2011 Requirements: a text file called 'input.txt' must be in the same directory where the executable for this program is run (current working directory). Assumptions: a line won't exceed 80 characters in length. */ #include int const MAX = 80; int main () { FILE *input_fp; char line [MAX]; input_fp = fopen ("input.txt", "r"); if (input_fp == NULL) printf ("File 'input.txt' cannot be opened."); else { printf ("File 'input.txt' opened for reading.\n"); printf ("-----------------------------------\n"); while (fgets (line, MAX, input_fp) != NULL) { printf ("%s", line); } printf ("\n\n"); } fclose (input_fp); printf ("-----------------------------------\n"); printf ("Finished reading from 'input.txt'. File is now closed.\n"); }