home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / LANGUAGS / MODULA2 / BENCH.MOD < prev    next >
Text File  |  2000-06-30  |  810b  |  35 lines

  1. (* Read a text and count the number of words with length
  2.    1, 2, ... , 20, and those with length greater than 20.
  3.    Words are separated by blanks or ends of lines. *)
  4.  
  5. MODULE wordlengths;
  6.  
  7. FROM InOut IMPORT WriteString, WriteLn, WriteCard, OpenInput, Read, Done;
  8.  
  9.  
  10. VAR i,k: CARDINAL;
  11.     ch: CHAR;
  12.     count: ARRAY [1..21] OF CARDINAL;
  13.  
  14. BEGIN
  15.   OpenInput('TEXT');
  16.   FOR i := 1 TO 21 DO count[i] := 0 END;
  17.   LOOP
  18.     Read(ch);
  19.     IF NOT Done THEN EXIT END;
  20.     IF ('A' <= CAP(ch)) AND (CAP(ch) <= 'Z') THEN
  21.       k := 0;
  22.       REPEAT
  23.         INC(k); Read(ch);
  24.       UNTIL (CAP(ch)< 'A') OR ('Z' < CAP(ch));
  25.       IF k > 20 THEN k := 21 END;
  26.       INC(count[k])
  27.     END
  28.   END;
  29.   WriteLn;
  30.   WriteString('  Length  Count');
  31.   FOR i := 1 TO 21 DO
  32.     WriteCard(i,6); WriteCard(count[i],6)
  33.   END
  34. END wordlengths.
  35.