467,161 Members | 994 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Counting the number of words read until end of file

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
  • viewed: 6045
Share:
3 Replies
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
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
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.

Similar topics

8 posts views Thread by DrNoose | last post: by
7 posts views Thread by sathyashrayan | last post: by
18 posts views Thread by Conrad F | last post: by
7 posts views Thread by peraklo@gmail.com | last post: by
11 posts views Thread by Andy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.