WOW....a lot of people seemed bummed that their school doesn't have computer programming...iwell, 'll be willing to share my class with those who are less fortunate to have programming classes over the summer....
WOW....a lot of people seemed bummed that their school doesn't have computer programming...iwell, 'll be willing to share my class with those who are less fortunate to have programming classes over the summer....
Oh yah tab, if charCount is equal to space or tab. Not EOF because the while statement ends when its at the EOF.Originally Posted by JoshR
BTW, my school only has 2 computer classes, networking and communications, and computer study, both are just basic crap. No programming classes, the person who said they have c++/java class are lucky.
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
He must have editted his post, because he said that he was just giving the topic creator an idea of how to do it, how to count spaces and such will give the topic creator an idea of how to count words. Which is what your topic was like also, to give the topic creator an idea, not give him the complete program.Originally Posted by dra
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
But...You have to know when the EOF has been found so you can count the last word
Counting spaces does not work.Originally Posted by dra
How many words are in this file:
Code:one two three
Last edited by Rashakil Fol; 07-10-2005 at 05:12 PM.
Ohhh yeah you're right you would if you were counting by spaces. In that case I'd use dra's code, count strings, thats the one I was thinking of cause I was playing with that code myself, it works well and easily.Originally Posted by JoshR
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
dae...how do you write the code if it counts the strings?
I dont know how I can help without giving you the program, its pretty much exactly what dra's code is:Originally Posted by jaybo684
Open the file, and instead of cin.. use the file. I dont know if using a string is more efficient than using a char and counting words based on spaces/tabs/n/and eof, but it works and the code is simple.Code:#include <iostream> #include <string> using namespace std; int main(){ string s; int i = 0; while ( cin >> s ){ i++; } cout << "You entered " << i << " words."; }
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101
it was just a suggestion....Originally Posted by Rashakil Fol
besides, assuming the sentences are properly written, as in one space between each word, and two after a sentence, he could probably get away with it.
But even then, it's too much work. Letting the library do all the work is best. lol.
Last edited by dra; 07-10-2005 at 10:54 PM.
5.4 and 5.5 is what I have to do...
http://www.santarosa.edu/~ssarkar/ci.../cis10/a5.html
I would just use a char array for 5.5
technically, you'd be reading it in character by character
Last edited by major_small; 07-10-2005 at 11:27 PM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
With all the "hints" given on this topic and on that actual page, theres a hints link, you should be able to figure it out. Dra's code implimented with what I said to do is 5.4 (with the addition of "asking for the filename to be opened (stored in a string)"). In 5.5 you simply do the same thing but instead of taking a string at a time from the file, take a char (as it says to do), and test if its a space, tab, end of line, or end of file, if it is then you add 1 to wordCount. In addition you could use a char array to store the output for 5.5, but thats pointless for this program as you can simple cout it 1 char at a time as it comes out.
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101