home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 109_01 / wc2.c < prev    next >
Text File  |  1985-03-10  |  1KB  |  52 lines

  1.  
  2. /**********************************************************
  3.  ***                            ***
  4.  ***    Copyright (c) 1981 by David M. Fogg        ***
  5.  ***                            ***
  6.  ***        2632 N.E. Fremont            ***
  7.  ***        Portland, OR 97212            ***
  8.  ***                            ***
  9.  ***        (503) 288-3502{HM} || 223-8033{WK}        ***
  10.  ***                            ***
  11.  ***    Permission is herewith granted for non-     ***
  12.  ***    commercial distribution through the BDS C    ***
  13.  ***    User's Group; any and all forms of commercial   ***
  14.  ***    redistribution are strenuously unwished-for.    ***
  15.  ***                            ***
  16.  **********************************************************/
  17.  
  18. /* ---> WC.C - COUNT CHARS/WORDS/LINES (BDS C VERSION) <--- */
  19.  
  20. #include <dmfio.h>
  21.  
  22. main (ac, av)
  23. int ac;
  24. char *av[];
  25. {
  26.    char c;
  27.    unsigned chars, words, lines;
  28.    BOOL inword;
  29.    char iobuf[BUFSIZ];
  30.  
  31.    inword = NO;
  32.    chars = words = lines = 0;
  33.  
  34.    if (ac < 2) errxit("Usage: wc filename");
  35.  
  36.    if (fopen(*++av, iobuf) == ERROR) errxit("File I/O Error");
  37.  
  38.    while ((c = getc(iobuf)) != CEOF && c != CPMEOF) {
  39.       ++chars;
  40.       if (c == '\n') ++lines;
  41.       if (isspace(c))
  42.      inword = NO;
  43.       else
  44.      if (inword == NO) {
  45.         inword = YES;
  46.         ++words;
  47.      }
  48.    }
  49.    printf("\nChars: %u   Words: %u   Lines: %u\n", chars, words, lines);
  50.    fclose(iobuf);
  51. }
  52.