By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,317 Members | 2,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,317 IT Pros & Developers. It's quick & easy.

Counting the number of words read until end of file

P: 24
I have a question which involves reading from cin and counting the number of words read until the end of file(eof).

The question is as follows:
Words are delimited by white spaces (blanks, tabs, linefeeds, returns). It will print 3 pieces of information
before exit: the first word, the last word, and the number of words read, with one blank in between fields.

Input
lines of words

Output
The first word, the last word, and the number of words read, with one blank in between fields.

Sample input
I like C++
It is easier than counting 1,2,3

Sample output
I 1,2,3 9

I am facing a major problem as i'm new to c++. Can anyone please help me... thanks soo much... i appreciate that...
Aug 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: 37
rgb
please refer to this link for some idea but not complete solution:
http://www.cplusplus.com/ref/cstring/strtok.html
Aug 31 '06 #2

P: 24
Nhd
please refer to this link for some idea but not complete solution:
http://www.cplusplus.com/ref/cstring/strtok.html
Hey, thanks alot.! appreciate that... :>
Aug 31 '06 #3

P: 37
rgb
sure, no problem... you just need to add some code to load the content of a file to a string (either partially thru buffer or all at the same time) and use it with the function to split and count all the words in the middle of first and last word with a counter.
Aug 31 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.