Having some trouble with some code. The rule is that if two characters must match, the duplicated letter must be deleted. So for example "Usually" would be changed to "Usualy".
The code does work however it doesn't do what was mentioned above.
I will post the code below and comment put a comment above the problem spot.
#include <iostream>
#include <list>
#include <ctype.h>
#include <fstream>
using namespace std;
void printList(const list<char> &myList);
void fillList(list<char> &myList);
void change(list <char> &myList);
void printList(const list<char> &myList)
{
list<char>::const_iterator itr;
for (itr = myList.begin(); itr != myList.end(); itr++ )
{
cout <<*itr;
}
cout << '\n' << endl;
}
void fillList(list<char> &myList)
{
ifstream file("test.txt");
string print;
while(file >> print)
{
for (int i = 0; i<=print.length(); i++)
{
myList.push_back(print[i]);
}
myList.push_back(' ');
}
}
void change(list <char> &myList)
{
list<char>::iterator itr;
//rules are as follows
//change w with v
for (itr = myList.begin(); itr != myList.end(); itr++ )
{
if (*itr == 'w')
{
*itr = 'v';
}
}
// double letter become single letter here
//PROBLEM IS HERE!
for (itr = myList.begin(); itr != myList.end(); itr++ )
{
std::list<char>::iterator itr2 = itr;
if(*(++itr2) == *itr)
{
myList.remove(*itr);
}
}
}
int main ()
{
list<char> myList;
ifstream file("test.txt");
const string print;
fillList(myList);
printList(myList);
change(myList);
printList(myList);
return 0;
}