You are here:

C++/counting repeated words in a string using pointers


given a paragraph(string) entered to your application by the user, it is possible to generate a report that contains information about the paragarph. the request information is:
1-how many sentences in the paragraph.
2-how many words in the paragraph.
3-how many characters in the paragraph.
4-how many repeated words in the paragraph.
5-for each repeated word it should give you how many times this word is repeated.
after getting the above report, your application should give the user the ability to search for a word and get a report how many times this word is repeated in the paragraph enterd before.
note that you SHOULD NOT use any ready (build-in) c/c++ functions in your code.
this is the assignment i must do, i did the first three requests, but i was stuck in counting the repeated words, i tried very hard but i couldn't catch the idea. please help me very soon, and thanx

salloum, ahmad , Thank you for your question.

There are several efficient ways to do this, but since your assignment looks elementary, you probably will bs satisfied with an inefficient (slow) solution that works.


Declare a dynamic list. Each element should contain a variable-length string and a numeric count.

1. Input the next word
2. Compare it with each element in the list of words (this list is initially empty)
3. If it is found, increment the counter in that element
4. If it is not found, add it to the list and increment the counter in that element
5. If more words remain, repeat at step 1.
6. If no more words remain, scan the list and display the words and their counters

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 All rights reserved.