My program should find any 4 letter words and change them into string "love" ... i have successfully found all the spaces and modified any 4 letter words before the spaces... however, the last word before the '/0' doesn't change... please help.
btw, is there any string class function check for if the the char is a capital letter? thank u
int main()
{
string sentence;
cout<<"Please enter a sentence."<<endl;
getline(cin,sentence);
int startIndex=0, endIndex=0;
for(int i=startIndex; i<sentence.size(); i++)
{
if((sentence[i]==' ')|| (sentence[i]=='/0'))
{ // i hate you very
endIndex=i;
if((endIndex-startIndex)==5)
{
sentence.replace(startIndex+1, 4, "love");
}
startIndex=i;
}
}
cout<<sentence;
return 0;
}