Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

[PASCAL]Count the number of words in text file

Jeffrey LeungJeffrey Leung Posts: 1

program counting;
uses crt, dos;
var
HA : text;
n : integer;
ch : char;
begin
assign(HA, 'haha.txt');
reset(HA);
n := 0;
while not eof(HA) do
begin
while not eoln(HA) do
begin
read(HA,ch);
n := n + 1;
end;
readln(HA);
end;

close(HA);
gotoxy(13,13);
write(n);
readln;
end.

{ n is used to show the number of words to users }
wt hv I done wrong? why there is run time error??

Comments

  • ActorActor Posts: 441 ✭✭

    What run time error are you getting. My guess is #2 "file not found." It can't find haha.txt.

    As is the program does not count words in a file. It counts total characters in the file.

Sign In or Register to comment.