The next program counts the number of characters in a file. The most noteworthy difference between the K&P version and this one is that a new line counts as 2 characters because in DOS it is two characters. Also my program is named CharCnt because the K&P name, charcount, is too long for a DOS name.
Program CharCnt ;
{
count characters in standard input
}
Var
Count : LongInt ;
Ch : Char ;
begin { CharCnt }
Count := 0 ;
while NOT eof do begin
Read (Ch) ;
Count := Count + 1
end ;
WriteLn (Count:0)
end. { CharCnt }
I have used Pascal's WriteLn procedure for output instead of K&P's
putdec mainly because at this point, page 13, K&B have not gotten around to defining putdec.
Look up the K&P version at
http://cm.bell-labs.com/cm/cs/who/bwk/pascaltools.txt
and search for "charcount"