this is a test question for my class so I've tried to keep it specifically like this:
I need to make a function called:
countWord(String p, String w)
the first parameter 'p' is to hold the paragraph
the second 'w' is to hold the word you want counted
the function is suppose to return a integer value of 0 or more depending on how often your word is found in the paragraph
this is what i have:
int countWord(String &p, String &w)
{
int counter, spacePos, nextspacePos = 0;
for (int i = 0; i < p.length(); i++)
{
spacePos = (p.substr( spacePos, p.length() ), ' ');
nextspacePos = (p.substr(spacePos, p.length()), ' ');
if (w == p.substr(spacePos + 1, w.length()))
{
counter++;
i = nextspacePos;
}
}
return(counter);
}