| | |
word count
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2005
Posts: 188
Reputation:
Solved Threads: 3
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
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.
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.
May 'the Google' be with you!
•
•
Join Date: Aug 2005
Posts: 188
Reputation:
Solved Threads: 3
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

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
![]() |
Similar Threads
- Word count help. (C++)
- Can you please help me write this word count program in another way (Python)
- I Need Help Writing A Word Count Program In My Python (Python)
- Need Help, basic word count, string manipulation (VB.NET)
- word count in borland c++ ?? (C++)
- word count (Java)
- I can't implement a word count into my text editor (JAVA) (Java)
Other Threads in the C++ Forum
- Previous Thread: Help in terminating a program
- Next Thread: char+int?????
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





