Solved

counts how many times each word occurs

Posted on 1998-10-19
4
289 Views
Last Modified: 2010-04-02
stores each word in the article in the two-dimensional array words.counts how many time each word occurs in the article
eg. a word such as 'the' presumably will occur many times in the article. store it once, but count the number of times it occurs. Print bout the stored words and their respective counts
0
Comment
Question by:wongmlai
4 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1175533
We cannot do your homework for you.  It is unethical and grounds for removal from this site (for both you and us.)

We can answer specific questions, like you might ask your teacher.
We can review your work and offer suggestions.

So do you have specific questions or would you like to attempt the problem and post what you get done?
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 1175534
what's the problem ? Start counting
0
 

Expert Comment

by:hawkett092198
ID: 1175535
Look, nietod's right - but here's a start

assuming you know somthing about whichever language you are programming it in (there are loads of ways to do this) -

   * Open the file
   * Start reading characters one by one
   * Treat spaces as word separators
   * Read each word into a buffer before you store it in the array
   * Check if the word already exists (increment if it does ,or store it if not)
   * When the file ends you have finished

(which is what AnswerTheMan said in two words - 'start counting')

I figure though, that this assignment is not aproblem solving exercise, and is
actually an exercise to teach you the language - so this is not going to be much help.  Let me guess - Exams coming up, assignment due, and you've been getting red-eyes from lack of both attendance and study?
0
 
LVL 1

Accepted Solution

by:
MatthewL earned 100 total points
ID: 1175536
Hi wongmlai;

You could use strtok with a token of " " to seperate the words.
Then search for each word using strstr.  Note that you will have to parse past the the found string.

i.e.

char *curSpot;
 
 . . .

curSpot = strstr( mainString, word );
curSpot += strlen( word );

Good Luck.

Matt  

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now