home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / PWBTUTOR / COUNTBUF.C$ / COUNTBUF
Encoding:
Text File  |  1991-08-12  |  1.1 KB  |  46 lines

  1. // COUNTBUF.C - Analyze the characters in one buffer.
  2. // Part of the multimodule example program used in the PWB tutorial.
  3. //
  4. // Increment Bytes. For each char, increment Characters, Lines,
  5. // and/or Words if appropriate. For each character, call Analyze.
  6. // (A character is defined as printable ASCII.)
  7. //
  8.  
  9. #include "count.h"
  10.  
  11. FLAG CountWords( FLAG InWord, int nChars )
  12. {
  13.     int Scan;
  14.     char curCode;
  15.  
  16.     Bytes += (long)nChars;
  17.  
  18.     for( Scan = 0; Scan <= nChars; ++Scan )
  19.     {
  20.         curCode = Buffer[Scan];
  21.         if( curCode == '\n' )
  22.             ++Lines;
  23.         if( !InWord )
  24.         {
  25.             if( curCode > ' ' )
  26.             {
  27.                 Analyze( curCode, InWord );
  28.                 InWord = TRUE;
  29.                 ++Words;
  30.                 ++Characters;
  31.             }
  32.         }
  33.         else
  34.         {
  35.             if( curCode <= ' ' )
  36.                 InWord = FALSE;
  37.             else
  38.             {
  39.                 ++Characters;
  40.                 Analyze( curCode, InWord );
  41.             }
  42.         }
  43.     }
  44.     return InWord;
  45. }
  46.