Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int totalWordsOn(string sentence)
- {
- int counter = 0;
- bool wordStarted = false;
- for (int i = 0; i < sentence.size(); ++i)
- {
- int ascii = int(sentence[i]);
- // A - Z = 65 - 90, a - z = 97 - 122
- if ((ascii >= 65 && ascii <= 90) || (ascii >= 97 && ascii <= 122))
- {
- if (wordStarted == false)
- {
- counter++;
- wordStarted = true;
- }
- }
- else
- {
- if (wordStarted == true)
- {
- wordStarted = false;
- }
- }
- }
- return counter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement