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

  • SEARCH
  • Home
  • 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 7616683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:56:54+00:00 2026-05-31T02:56:54+00:00

I have googled this question and couldn’t find an answer that worked with my

  • 0

I have googled this question and couldn’t find an answer that worked with my code so i wrote this to get the frequency of the words the only issue is that i am getting the wrong number of occurrences of words apart form one that i think is a fluke. Also i am checking to see if a word has already been entered into the vector so i don’t count the same word twice.

fileSize = textFile.size();
vector<wordFrequency> words (fileSize);
int index = 0;
for(int i = 0; i <= fileSize - 1; i++)
{
    for(int j = 0; j < fileSize - 1; j++)
    {
        if(string::npos != textFile[i].find(textFile[j]) && words[i].Word != textFile[j])
        {
            words[j].Word = textFile[i];
            words[j].Times = index++;
        }
    }
    index = 0;
}

Any help would be appreciated.

  • 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-05-31T02:56:55+00:00Added an answer on May 31, 2026 at 2:56 am

    try this code instead if you do not want to use a map container..

        struct wordFreq{
        string word;
        int count;
        wordFreq(string str, int c):word(str),count(c){}
        };
    vector<wordFreq> words;
    
    int ffind(vector<wordFreq>::iterator i, vector<wordFreq>::iterator j, string s)
    {
        for(;i<j;i++){
            if((*i).word == s)
                return 1;
        }
        return 0;
    }
    

    Code for finding the no of occurrences in a textfile vector is then:

    for(int i=0; i< textfile.size();i++){
        if(ffind(words.begin(),words.end(),textfile[i]))    // Check whether word already checked for, if so move to the next one, i.e. avoid repetitions
            continue;
        words.push_back(wordFreq(textfile[i],1));          // Add the word to vector as it was not checked before and set its count to 1
        for(int j = i+1;j<textfile.size();j++){            // find possible duplicates of textfile[i]
            if(file[j] == (*(words.end()-1)).word)
                (*(words.end()-1)).count++;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I googled this question and couldn't find an answer. I am trying to have
I googled this question and I couldn't find an answer. I have a page
This question may have been asked before, but I couldn't find an answer to
I have googled this a little and didn't really find the answer I needed.
I've googled this question repeatedly, but have not found a great answer anywhere. I'm
Before asking this question I have googled for some time, but could not find
I thought this question would have been asked before, but I couldn't find it
I couldn't find a good answer for this question so I figured I'd ask.
I am new to Emacs. I have googled this but no good answer there.
I have asked this question here about a Python command that fetches a URL

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.