strtok help on a word frequency program

This is a discussion on strtok help on a word frequency program within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm new to C++ and I am stuck on a problem I was assigned. Below is the problem statement ...

strtok help on a word frequency program

Hello, I'm new to C++ and I am stuck on a problem I was assigned. Below is the problem statement and I will post my code as well.

Write a C++ program that reads one line of text from the user via the keyboard, then reports the frequency of the word lengths found in that line of text. Here is a sample run of the program. The program first asks the user to enter a line of text:

Enter a line of text:

Then, the user types in a line such as this one (the user can type in any text of up to 80 characters):

The cat ran down the road. Meanwhile, a storm was gathering.

Requirements

1. Put your solution in a file name "WordFreq.cpp". You can have other files if you wish (the main function should be in WordFreq.cpp).
2. The user can type up to an 80 character line. Therefore, the longest possible word can be 80 characters.
3. Your "Word Frequency Report" should report up to and including the longest word found, and not beyond that length. For example, if the longest word in the user's input is three characters, then the report should go from 1 to 3. If the longest word in the user input was 21 characters, then the report should go from 1 to 21. In the sample run of the program, above, the longest words were of length ten, so the report went from 1 to 10. The longest possible word is 80 characters. In the second sample run of the program, below, the longest word was five characters so only word lenghths of 1 to 5 were reported. Your program should automatically adjust the length of the report.

Hints

1. You can use the cin.getline function to read a line of text from the user. See the textbook for details on getline.
2. You can use function strtok to break a line into its separate words. I posted a video on how to use strtok that you might want to look at (strtok is also covered in the textbook).
3. Get an early start on the program. If you get stuck you can send me your code via email.

Like I said I'm new to programming all together so this seems very difficult me. My output for that just counts the first token and also the amount of words in the input. So if someone was to input...."I hate this program" the output would read....
1
1
1
1 1 being the amount in the first token and repeated 4 times for the amount of words in the input. I basically need to figure out how to get past the first token, and also how to implement the array and make a count on said array.

You can use strlen to count the string length. So, you can get rid of the for loop.
Also, when you call strtok in the while loop, you are overwriting the first substring pointer gotten using the call to strtok before the while loop. So, move the second call to strtok at the end of while loop like this: