I'd usetest exactly for a space (ie isspacetext[i] == ' '
) rather than isblank
and adding 1 at the end is expected, since if you have text like "Hello there", you'll count 1 space but there are 2 words. Just be sure you update your words
variable so your later calculation will be correct. (alternatively, initialize words to 1, since you know you won't ever have zero).