944,103 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 6406
  • C++ RSS
Aug 24th, 2005
0

word count

Expand Post »
As you may already know im working on a program that analyses a file given by the user, i want to create a word count feature. How would i go about doing this, i mean how would i distinguish what is exactly is a word and be able to incorporate this into my code, im not specifically looking for any example code on this 1, more just ideas on the method, any links or tips could be useful. Thanks
Similar Threads
Reputation Points: 23
Solved Threads: 5
Posting Whiz in Training
bops is offline Offline
214 posts
since Aug 2005
Aug 24th, 2005
0

Re: word count

Words are generaly seperated by spaces, so look for spaces between charaters.
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
zyruz is offline Offline
60 posts
since Jun 2005
Aug 24th, 2005
0

Re: word count

More precisely, look for spaces ONLY after characters.
That will help you a great deal with tabs and incorrect spacing.
Reputation Points: 22
Solved Threads: 5
Posting Whiz in Training
Drowzee is offline Offline
244 posts
since Jul 2005
Aug 25th, 2005
0

Re: word count

Do you want to do this in C or C++. For C++ see the code snippet at:
http://www.daniweb.com/code/snippet225.html

With C you have to slug it out in the trenches! Not too hard to do, just labor! A word can end with a space, tab, period, comma, semicolon, newline, ? or ! and so on. Simply count all the isalpha(characters) that are followed by on of those endings.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Aug 25th, 2005
0

Re: word count

Thanks a lot guys, I actually thought of spaces at first but then as i though deeper i got a bit confused on how i would write the code, but it is done now and works fine. I decided to store the file in an array and check if the character proceeding the 1 in question was a space, tab or newline, and then counted this as a word, i have also tried to take into account a word at the end of the file that may not have a leading character. This may not be so accurate but it works fine on all of my tests i have done. Thanks for the tips guys, if anyone wants me to post teh code just let me know in this thread

I was using c++ by the way (Dev-C++) vegaseat, and what are you doing up so early lol :p oh wait different time zone, my bad lol
Reputation Points: 23
Solved Threads: 5
Posting Whiz in Training
bops is offline Offline
214 posts
since Aug 2005
Aug 26th, 2005
0

Re: word count

<<Moderator edit: Pointless flame-bait>>
Last edited by Narue; Aug 26th, 2005 at 11:49 pm. Reason: Let's not be bitter, k?
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Feb 25th, 2007
-1

Re: word count

can you post the code?
Reputation Points: 9
Solved Threads: 1
Newbie Poster
Kcin is offline Offline
16 posts
since Feb 2007
Feb 25th, 2007
0

Re: word count

>can you post the code?
No, because this thread is two years old.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: Help in terminating a program
Next Thread in C++ Forum Timeline: char+int?????





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


Follow us on Twitter


© 2011 DaniWeb® LLC