Skip to main content
changed advice
Source Link
curiouskiwi
  • 18.7k
  • 2
  • 18
  • 43

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).

I'd use isspace 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).

I'd test exactly for a space (ie text[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).

Source Link
curiouskiwi
  • 18.7k
  • 2
  • 18
  • 43

I'd use isspace 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).