954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Difficult C Question

I need the coding for the following question in C:
Read from a file (.txt file) and count the number of times the word "a", "is", "the", "and", "that", and "this" occurs.

junezy4
Newbie Poster
3 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

We provide help, or answers to specific questions..So what have you tried so far? What is your specific question?

gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
 

One way to do that is to create a structure that contains the strings and an integer

struct words
{
    char* word;
    int count;
};


Now make a simple array of these structures and initialize all counts to 0 and character arrays to the words in the list you posted.

Next, open and read the file one word at a time. fscanf("%s" ...) would be best in this program. For each word read, search the array for it and if found increment the counter.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This sounds like a homework question, I think you need to go through and think what you need to do.

targ2002
Newbie Poster
1 post since Feb 2010
Reputation Points: 8
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: