• Status: Solved
• Priority: Medium
• Security: Public
• Views: 351

# counts how many times each word occurs

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
wongmlai
1 Solution

Commented:
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

Commented:
what's the problem ? Start counting
0

Commented:
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

Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.