Something woring with counting words

Hi, there is something missing in my code. Can someone point out which part I am missing?

1
2
3
4
5
6
7
8
9
10
11
void countWord (list <char> &myList)
   {
   list<char>::iterator itr;
   int count = 0;
   for (itr = myList.begin(); itr != myList.end(); itr++)
   {
   if ((*itr) == ' ' || (*itr) == ',' || (*itr) == '.' || (*itr) == '!' || (*itr) == '?' || (*itr) == '-')
   count ++;
   }
   cout << "Number of words are " << count << "\n";
   }



Def:
a.txt = What do you eat? What meat
b.txt = What do you eat? What meat?

When I try
./a.out a.txt
Number of words are 6
./a.out b.txt
Number of words are 7

Thanks before for your help :)
You increase the count when you encounter a '?". You have one more '?' in b.txt with all else being equal, so naturally the count is one higher for b.txt.
Yep, that's right! :) Thanks for you help! :)
Topic archived. No new replies allowed.