Jump to content

[PASCAL] WordCounter


CouldnoT
 Share

Recommended Posts

Word Counter

 

This is a small program that allows you to count how many words there are in a text.

Here is the script :

 

program counter;

uses crt;
 
var
text: string;
x, c: Integer;
 
procedure count;
begin
    delete (text, x, 1);
    c:= c+1;
end;
 
begin
textcolor(white);
writeln('Welcome to the word counter');
write('enter the text : '); 
textcolor(lightblue);
readln(text);
textcolor(white);
c:= 0;
 
repeat 
begin
    x:= pos(' ', text);
    count;
end;    
until(x = 0);
 
If c < 20 then
    writeln('There is ' ,c, ' words.')
Else
    writeln('There is ' ,c, ' word.');

readkey;
end.

 

This counter works by eliminating every time a space from the text and adds +1 in each loop until the number of spaces is zero (position is zero).   

PS : the position of x should be also integrated in the loop so that the variable gets the new position on each time the loop works.

Edited by CouldnoT
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.