home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / words.zip / wcount.c next >
C/C++ Source or Header  |  1994-06-24  |  524b  |  32 lines

  1. /* WCOUNT.C */
  2.  
  3. /* (c) 1994, Matt McLeod */
  4. /* See WORDS.C for license info */
  5.  
  6. /* This is the "word-counting" engine for WORDS.  */
  7.  
  8. #include <stdio.h>
  9. #include <ctype.h>
  10.  
  11. #define BOOL int
  12. #define TRUE 1
  13. #define FALSE 0
  14.  
  15. int count_words (FILE *thefile)
  16. {
  17.     BOOL last_space = FALSE;
  18.     int words = 0;
  19.     char charin;
  20.  
  21.     while (!feof(thefile))
  22.     {
  23.         charin = fgetc(thefile);
  24.         if (isspace(charin) && !last_space)
  25.         {
  26.             words++;
  27.             last_space = TRUE;
  28.         } else last_space = FALSE;
  29.     }
  30.     return words;
  31. };
  32.