Longest Word in String - 16 lines source = Whopping 23K Executable!


/ Published in: Pascal
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. {Zouhair2.pas}
  2. Var
  3. S:String;
  4. l:Byte Absolute S;
  5. m,c:byte;
  6.  
  7. Label lp;
  8.  
  9. Begin
  10. WriteLn('enter your string below this line then press the enter key');
  11. Readln(S);
  12. lp:
  13. if S[l] in [' ','.',',',':',';']
  14. then c:=0 else Begin inc(c); if m<c then m:=c; End;
  15. Dec(l); if l>0 then goto lp;
  16. WriteLn(m,' characters is the length of the longest word in that string');
  17. End.

URL: pastebin.ca/2496436

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.