Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8706033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:30:47+00:00 2026-06-13T03:30:47+00:00

I want to count word frequency from a article. My thought is first create

  • 0

I want to count word frequency from a article.

My thought is first create a struct array

 struct{
       char[WORD_SIZE]
 }data[MAX_WORD_NUMBER];

and then read each character then determine by

isalpha();

and then convert to lowercase by

tolower();

then store a word to each struct.

then make failure function for every word,

then test each word by call it.

1.But I don’t know how to count the frequency due to repetition has caused.

(I thought I can compare it each time when I read and insert a word, but it is so ineffective, is there a more efficient way?)

2.I think that my method call function too many time.

How can I use KMP more effectively?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:30:48+00:00Added an answer on June 13, 2026 at 3:30 am

    You are programming in C or C++? You tagged your question with both.

    Assuming you are using C++ then you are going to do much better with std::map to count your words. Something like this

    #include <map>
    #include <string>
    
    std::map<std::string, int> data;
    
    std::string word;
    
    data[word] = 0; // set word count to zero
    data[word]++; // increment word count
    
    // print out all the word counts
    for (std::map<std::string, int>::iterator i = data.begin();
      i != data.end(); ++i)
    {
      cout << "word " << i->first << " occurs " << i->second << "times\n";
    }
    

    This task will be so much easier if you choose the right tools for the job. Of course if you are programming in C then none of this is going to help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read data from a bunch or emails and count frequency of each word.
I read data from a bunch or emails and count frequency of each word.
How can I integrate word count into bassistance.de validation? For example, i dont want
I want to count the number of accounts from the resulting table generated from
I'm trying to create a word count (for any page) bookmarklet without loading an
I want to count the number of genes from a text file using the
I have this string: $array= 'orange, fruit, apple juice' I want to count the
i have the following associative array word => count where word is an english
Is that possible to get the words count from the MS Word without the
I want to count number of occurence of BB code like word (example: [b]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.