/* Program 6 */
#include <stdio_h>

/*  #define YES 1
    #define NO  0
      The two constants are defined in stdio_h for this
      implementation, but may not be for others
*/

   main () {
      int c, fd, nl, nw, nc, word;
      char file[20];

      printf("Enter File: ");
      gets(file);
      fd = fopen(file,"r");
      if (fd == NULL) {
         printf("File Open Error");
         abort(1);
      }
      word = NO;
      nl = nw = nc = 0;

      while (( c = getc(fd)) != EOF) {
         ++nc;
         if ( c == '\n')
            ++nl;
         if ( c == ' ' || c == '\n' || c == '\t')
            word = NO;
            else if (word == NO) {
               word = YES;
               ++nw;
            }
      }
      fclose(fd);
      printf("Lines: %d  Words: %d  Chars: %d",nl,nw,nc);
   }

