/ Published in: Pascal
                    
                                        
I compiled this 16 line program with freepascal , and it was 23K ! Zouhair Tele asked :
Count the number of words in a given string. Word is a sequence of characters separated by spaces or punctuation marks (dot, comma, semicolon, colon).
For example: the string “abc d, efg,..hijkl.mno†- 5
Working with Strings
please can you help me with this
                Count the number of words in a given string. Word is a sequence of characters separated by spaces or punctuation marks (dot, comma, semicolon, colon).
For example: the string “abc d, efg,..hijkl.mno†- 5
Working with Strings
please can you help me with this
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
{Zouhair2.pas}
Var
S:String;
l:Byte Absolute S;
m,c:byte;
Label lp;
Begin
WriteLn('enter your string below this line then press the enter key');
Readln(S);
lp:
if S[l] in [' ','.',',',':',';']
then c:=0 else Begin inc(c); if m<c then m:=c; End;
Dec(l); if l>0 then goto lp;
WriteLn(m,' characters is the length of the longest word in that string');
End.
URL: pastebin.ca/2496436
Comments
 Subscribe to comments
                    Subscribe to comments
                
                