error string subscript out of range- WHY???

/**
Find words in stream, places them in a string, finds the beginning and end position of the interior letters of the word and creates a string to hold the interior words,
jumbles interior letters, and recopies them into original vector
@param file being read
@returns the string line
*/
string findwords(string line, unsigned startpos)
{
while(startpos != line.length())
{
while(isspace(line[startpos]))
{
startpos++;
}
unsigned endpos = startpos;
while(!isspace(line[endpos]))
{
endpos++;
}
endpos--;
unsigned wordlength = endpos - startpos;
string word = line.substr(startpos, (wordlength + 1)); //creates a string to hold the characters of the word
unsigned begletter = startpos;
while(!isalpha(word[begletter]))
{
begletter++;
}
unsigned endletter = endpos;
while (!isalpha(word[endletter]))
{
endletter--;
}
if((endletter - begletter) >= 3) ///determines if the word is longer than 3 letters
{
unsigned startletter = begletter - startpos; //gives position of the first letter for the word array
unsigned finletter = endletter - begletter;
string wordletters = word.substr(startletter, (finletter + 1)); //creates a string to hold the letters of the word
unsigned begword = 1; //variable for position of second letter in the word (aka: first interior letter)
unsigned endword = finletter - 1; //variable for position of last interior letter
string interiorchar = wordletters.substr(begword, endword); //creates a string to hold the interior characters of the word
int nowsize = interiorchar.length();
jumble(nowsize);
for(int i = 0; i <= (endword - 1); i++)
{
wordletters[(i + 1)] = interiorchar[i]; //copies jumbled characters into their positions within the word letters
}
for (int i = 0; i <= finletter; i++)
{
word[(startletter + i)] = wordletters[i];
}
for (int i = 0; i <= wordlength; i++)
{
line[(startpos + i)] = word[i]; //copies jumbled word into its spot in the line
}
}
if (endpos < (line.length() - 1))
{
startpos= endpos + 1;
}
else if (endpos == (line.length() - 1))
{
startpos = line.length();
}
}
return line;
}
Last edited on
What line is the error occurring on? And please use [code] tags.
Topic archived. No new replies allowed.