home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / flex-2.4.7-src.lha / GNU / src / amiga / flex-2.4.7 / MISC / fastwc / mywc.c next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  418 b   |  27 lines

  1. /* A simple but fairly efficient C version of the Unix "wc" tool */
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5.  
  6. main()
  7. {
  8.     register int c, cc = 0, wc = 0, lc = 0;
  9.     FILE *f = stdin;
  10.  
  11.     while ((c = getc(f)) != EOF) {
  12.         ++cc;
  13.         if (isgraph(c)) {
  14.             ++wc;
  15.             do {
  16.                 c = getc(f);
  17.                 if (c == EOF)
  18.                     goto done;
  19.                 ++cc;
  20.             } while (isgraph(c));
  21.         }
  22.         if (c == '\n')
  23.             ++lc;
  24.     }
  25. done:    printf( "%8d%8d%8d\n", lc, wc, cc );
  26. }
  27.