Solved

counts how many times each word occurs

Posted on 1998-10-19
4
296 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

929 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

17 Experts available now in Live!

Get 1:1 Help Now