pascal word and letter counting

Reply

Join Date: Oct 2006
Posts: 1
Reputation: tom3005 is an unknown quantity at this point 
Solved Threads: 0
tom3005 tom3005 is offline Offline
Newbie Poster

pascal word and letter counting

 
0
  #1
Oct 19th, 2006
hey

I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.

I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!

Any help getting started would be much appreciated

tom
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 71
Reputation: Micheus is an unknown quantity at this point 
Solved Threads: 4
Micheus's Avatar
Micheus Micheus is offline Offline
Junior Poster in Training

Re: pascal word and letter counting

 
0
  #2
Oct 26th, 2006
Originally Posted by tom3005 View Post
hey

I am learning pascal and need to write a program where, when the user enters a sentence finishing with a full stop it prints the number of words in the sentance and the number of words with over 3 letters in.

I have no idea how to count the words in a sentance or the letters in a word. I also dont no how to regonise the full stop as the end of the sentence. So as you can see im quite stuck!

Any help getting started would be much appreciated

tom
You can count words in a sentance by looking for space character (or carrie return if present - Does is possible?) until the end of sentance (full stop ???). So, extracting word by word from sentance you can count how many letters it has in too.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 3
Reputation: WhiteAvenger is an unknown quantity at this point 
Solved Threads: 0
WhiteAvenger WhiteAvenger is offline Offline
Newbie Poster

Re: pascal word and letter counting

 
0
  #3
Oct 30th, 2006
If you need help getting started, These are Code Blocks I'd use:

To get the length of a string:
  1. length(<somestring>) {This gives you - have a guess - the Length of a string.}

To get only the string until the full stop:
  1. var ct:Integer; somestring, croppedString:String; Flag:Boolean;
  2. ...
  3. Begin
  4. ...
  5. Flag := False;
  6. ct:= 0;
  7. While not Flag Do
  8. Begin
  9. Inc(ct);
  10. Flag := (somestring[ct] = '.') or (ct = length(somestring)); {somestring[2] gives you the 2nd letter of the string.}
  11. End;
  12. croppedString:= copy(somestring, 1,ct); {copy(String, Index, Count) gives you the "count" letters after "Index".}
  13. ...
  14. End.

To count the number of letters:
  1. var ct,NumOfLetters: Integer; somestring: String;
  2. ...
  3. Begin
  4. ...
  5. NumOfLetters := 0;
  6. For ct:= 1 to length(somestring) Do
  7. If (somestring[ct] <> ' ') Then Inc(NumOfLetters); {Increase NumOfLetters.}
  8. ...
  9. End.

I'll have to think about how to count the number of words with over three letters, though - I'll try to post it tomorrow.

Greetz

WhiteAvenger
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC