home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tyc / list16_7.c < prev    next >
C/C++ Source or Header  |  1993-10-16  |  610b  |  33 lines

  1.  /* Detecting end-of-file. */
  2.  
  3.  #include <stdio.h>
  4.  
  5.  #define BUFSIZE 100
  6.  
  7.  main()
  8.  {
  9.      char buf[BUFSIZE];
  10.      char filename[20];
  11.      FILE *fp;
  12.  
  13.      puts("Enter name of text file to display: ");
  14.      gets(filename);
  15.  
  16.      /* Open the file for reading. */
  17.      if ( (fp = fopen(filename, "r")) == NULL)
  18.      {
  19.          fprintf(stderr, "Error opening file.");
  20.          exit(1);
  21.      }
  22.  
  23.      /* If end of file not reached, read a line and display it. */
  24.  
  25.      while ( !feof(fp) )
  26.      {
  27.          fgets(buf, BUFSIZE, fp);
  28.          printf("%s",buf);
  29.      }
  30.  
  31.      fclose(fp);
  32.  }
  33.