The first LETTER or the first letter after a space or punctuation mark, should be where your program increments the word count.
Originally Posted by strugglesWithC
So basically, you have two states to contend with as you "walk" through the string, char by char:
1) your program is OUTSIDE a word. No words get incremented here,
2) your program is INSIDE a word, and the word counting variable will be incremented, first thing.
Aside from that algorithmic change, the only difference with your previous program is that you will add the punctuation marks, into the same if() statement that you have used before, for spaces.
type of thing. Add in all the punctuation marks that you need, in the same way.
if(char==' ' || char==',' || char=='.' || char=='\n')
Use that kind of if statement, inside your while loop, and you're off to a great start.