944,173 Members | Top Members by Rank

Ad:
Oct 19th, 2006
-1

pascal word and letter counting

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tom3005 is offline Offline
1 posts
since Oct 2006
Oct 26th, 2006
0

Re: pascal word and letter counting

Click to Expand / Collapse  Quote originally posted by tom3005 ...
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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Micheus is offline Offline
72 posts
since Jun 2006
Oct 30th, 2006
0

Re: pascal word and letter counting

If you need help getting started, These are Code Blocks I'd use:

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

To get only the string until the full stop:
pascal Syntax (Toggle Plain Text)
  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:
pascal Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WhiteAvenger is offline Offline
3 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Compound Control Class
Next Thread in Pascal and Delphi Forum Timeline: Dialog Box Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC