home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / SNAKEOIL.ZIP / WC.C < prev   
Encoding:
C/C++ Source or Header  |  1988-07-28  |  1.3 KB  |  52 lines

  1. /*************************************************************************
  2.  Copyright (c) 1984 All Rights Reserved                   Karl L. Remmler
  3.  Not for commercial use or profit
  4.  
  5.               WC.c - word count and redirected IO      (CI-C86)
  6.  
  7.   NOTE #1: See K&R, Chapters 1 and 7.2, pages 18 and 144, respectively.
  8.  
  9.   NOTE #2: USAGE: ex28 <filename
  10.  
  11. **************************************************************************/
  12.   
  13. #define HEATH        /* . . . . . . . . . .  delete this line for IBM-PC */
  14.   
  15. #define puts printf  /* . . . . . . . . . . . . . .conversion from BDS-C */
  16. #include "stdio.h"
  17.  
  18. #ifdef HEATH
  19. #include "heath.h"
  20. #linclude "locate.c"
  21. #else
  22. #include "ibm.h"
  23. #endif
  24.  
  25. main()
  26. {
  27.     int c, nl, nw, nc, inword;
  28.  
  29.     inword = NO;
  30.     nl = nw = nc = 0;
  31.     while ((c = getchar()) != EOF) {
  32.     ++nc;
  33.     if (c == '\n')
  34.          ++nl;
  35.     if (c == ' ' || c == '\n' || c == '\t')
  36.          inword = NO;
  37.     else if (inword == NO) {
  38.          inword = YES;
  39.          ++nw;
  40.     }
  41.     }
  42.     CLS;
  43.     locate(10, 30);
  44.     printf("%d lines", nl);
  45.     locate(12, 30);
  46.     printf("%d words", nw);
  47.     locate(14, 30);
  48.     printf("%d characters", nc);
  49.     CUH;
  50.     exit();
  51. }
  52.