hi guys,
heres the problem. i have an assignment to change certain letters or combination of letters into some other letters or just to make them dissapier. Say like.. "the" to>> "ze", where "th" is replaced with "z". the program is consists of functions like these. checking two letters forward is fine.. iam using an ITERATOR to move-about
but the problem starts here...going back wards 3 nodes...
i have to make a way to get rid of the last "e" on words..but only on words of more than 3 letters.
say like: "here" would be "her"....
"bre" would still be "bre"..."ze" would still be "ze"
>the way i'm trying to do is using a while loop and checking if words are more than 3 letters long....if they are i apply changes....
>if i come accross nodes other than "alphabetical" (like a "space")within 3 nodes back the loop breaks..do nothing..change nothing...
please refer to code :)
void ReplaceE(list <char> &myList)
{int count = 0;
list<char>::iterator itr; //main iterator
list<char>::iterator it; //another iterator
for (itr = myList.begin(); itr != myList.end(); itr++ )
if ((tolower(*itr) == 'e') ) // check for an "e"
{
itr++;
if((*itr) == ' ') // if the next node is a space countinue following
{
itr--; //on 'e'
it = itr; //assign the value to another iterator
while(count != 3)
{
itr--;
if(isalpha(*itr)) //check if passing "abc"s
{
count ++;
}
else
break; // if come accross non "abc" break
}
if (count == 3) // assumed never happens if word is only 3 ltrs
{
*it =' '; //change the node("e") to a " "
}
}
}
}
but it doesnt work. even the 2 letter worrds get affected. like "ze" becomes "z". lol i have tried so may variations of the "while loop" changing the variables with out any luck. some times the program gets aborted :(. ( at times it says "list iterator not incrementable")
--(i am using myList.unique() to get rid of the double charactors which get left by the above functions..not good but for the time being..)--
Please if you could point me what i am doing wrong here. i would much apriciate it. have been doing this allnight hehe.
thanks guys.
yaka.