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?
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::mapto count your words. Something like thisThis 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.