ATTENTION!!!: This assignment is for a basic and introductory C++ course. As suc
ID: 3836506 • Letter: A
Question
ATTENTION!!!: This assignment is for a basic and introductory C++ course. As such, please do not use complex or obscure opperations and headers that would typically be used in advanced classes as we have not learned them yet. Use only very simple functions and headers. If you are unsure of whether a technique is too advanced, dont use it. If you can answer the question without using a function, please do so.
"C type" string is implied to mean an array of characters with an end of string mark following the last character.
Write a function named WordCount, which determines the number of words in a "C type" string. The function will have one parameter (the address of the string) and will return the number of words (words are seperated by one or more spaces).
Explanation / Answer
Here is the code for you:
int wordCount(char* words)
{
int count = 1;
int i = 0;
while(words[i] != '')
{
if(words[i] == ' ' && words[i-1] != ' ')
count++;
i++;
}
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.