472,119 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Counting the number of words read until end of file

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
3 6233
rgb
37
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
24
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
37
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
11 posts views Thread by Andy | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.