word counting function not working properly

I am reading in a file that says:
The moving finger writes and having writ moves on
nor all the piety nor wit shall lure it back to cancel half
a line nor all the tears wash out a word of it

i am printing out a table that tells you how many words are in the file and i was given this function to put into my code which tells you how many words are in the file but when i run my program the words "it" and "the" have the values 3 instead of 2. i am not sure how to get the correct values for those words. any help appreciated, thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// *********************************************************************
// * Member Function:  WordCounter                                     *
// * Description:  Accept a word string, check the list to see if      *
// *    exists, increment the counter if it does, make it uppercase    *
// *    and add it to the list of words in alphabetical order.         *
// * Parameter List:  const string word:  Word to be inserted.         *
// * Author: Dr. David A. Gaitros                                      *
// * Date: Nov 1st, 2011                                               *
// *********************************************************************

void WordCounter::Addword (const string word)
{
  string tempword = Uppercase(word);
  static struct WordStruct * NewWord;
  if (Findword(word))
    {  Curr->Counter++;
         return;
    }
      
  Curr = Head;
  while(tempword > Curr->Wordobject)
    Curr=Curr->Next;
  NewWord = new WordStruct; 
  NewWord->Wordobject = tempword; 
  NewWord->Counter = 1;
  
  NewWord->Next = Curr;
  NewWord->Prev = Curr->Prev;
  Curr->Prev = NewWord; 
  NewWord->Prev->Next=NewWord;
 
}
I see "the" 3 times in the text. As for "it", my guess is that you add the word "it" twice at the end. Make sure that you are reading the correct number of words
Topic archived. No new replies allowed.