This is the text file I have written :
this is the first line
this is the first line
this is the second line
this is the second line
this is the second line
this is the third line
this is the first line
I am trying to remove the adjacent duplicate strings, so the output would be:
this is the first line
this is the second line
this is the third line
this is the first line
This is what I have written so far :
for(int i = 0; i < n; i++)
getline(infile,arr[i]);
for(int i=0; i<n; i++)
{
int j = i+1;
if(arr[i] == arr[j])
{
for(int k = i; k<n; k++)
arr[k] = arr[k+1];
n--;
}
}
this is the output I get:
this is the first line
this is the second line
this is the second line
this is the third line
this is the first line
How to fix this? P.S.: It has to be solved iteratively, which is why I'm trying to do it this way.
arr?