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
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.
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
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.