Posted By

MalcolmX86 on 12/12/13


String pascal Zouhair

Versions (?)

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

 / 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

  1. {Zouhair2.pas}
  2. Var
  3. S:String;
  4. l:Byte Absolute S;
  5. m,c:byte;
  7. Label lp;
  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.

Report this snippet  

You need to login to post a comment.