I'm working on a homework assignment, and I can't seem to get this function right. Does anyone have any ideas on why this won't work to create a substring consisting of the characters in between two spaces (word 0, word 1, etc...)?
string extractWord(string s, int wordNum)
{
int wordIndices[10];
int i = 0;
for (int z = 0; z < s.length(); z++)
{
if (isspace(s.at(z))==true)
{
wordIndices[i] = z;
i++;
}
}
return s.substr(wordIndices[wordNum], abs(wordIndices[wordNum+1] - wordIndices[wordNum]));
}