You are here:

C++/another doubt on writing a program

Advertisement


Question
QUESTION: how to write a c program that count the total number of words&the number of repeated words in a given text file.

ANSWER: Dear dhanapriya :

First you sort all the words in the text file.  

Then count all of the repeated words.  You will know they are repeated words because there will be more than one entry in a row in the sorted words.  

Then you remove the extra words from the sorted results and leave all the unique words to count the total number of words.  Actually there are two counts of the total number of words:  The total number of words in the whole file and the total number of unique words in the file.  Make sure you know which total you need.

---------- FOLLOW-UP ----------

QUESTION: how to write c program that will count total two,three,four lettered words in a given paragraph

Answer
Go through the paragraph and put all of the words excluding spaces and punctuation into an array of null terminated strings.  Sort the array of words.  Then use strlen the count the number of characters in each word.  Every time you find a two letter word increment a counter and so on.  Again be clear whether you need the total number of unique words or just a total number of words unique or non-unique.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Titus B. Ledbetter, Jr.

Expertise

C , MFC, Object Oriented, Artificial Intelligence

Experience

I have over ten years experience in the field of Computer Science, five years experience developing C/C++. I recently wrote a chess program using Object Oriented, C++, MFC.

Education/Credentials
Master's Degree Computer Science from Johns Hopkins

©2016 About.com. All rights reserved.