{*************************************************************** Count words in file. Prints a count of the words in a file. A 'word' is defined as any run of letters, digits or combinations thereof. ***************************************************************} program wcount(input, output); var wc: 0..maxint; { count of words } InWord: boolean; { word state } source: text; { input file } begin InWord := false; { set not in a word } wc := 0; { initalize counter } while not eof do begin { read thru entire file } if input^ in ['a'..'z', 'A'..'Z', '0'..'9'] then begin { in word } if not InWord then wc := wc + 1; { just entered, count word } InWord := true { set in word } end else InWord := false; { out of word } get(input) { next character, including eoln } end; writeln(wc:1, ' words in file') end.