/* file1.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 word won't exceed 80 characters in length. A program that reads from a file a word at a the time and echos what was read onscreen. */ #include const int SIZE = 80; int main () { FILE *input_fp; char word [SIZE]; 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"); while (fscanf (input_fp, "%s", word) >= 0) { printf ("%s ", word); } } fclose (input_fp); printf ("Finished reading from 'input.txt'. File is now closed.\n"); }