I'm trying to create a function that will detect if there are consecutive lines in a char array that are identical.
For example, if a char array contained:
Hi
Hello
Hello
Hello
Hello
then the array would be changed to
Hi
Hello
Essentially, I want to detect the consecutive, identical lines, and delete them so only one of the lines remains. If one line is identical to a earlier line, but they are not consecutive, then it's fine.
Really, the whole line doesn't have to be identical, but at least the first 79, or MAXCHARS, have to be identical.
Additionally, I don't want to do this by writing to an intermediate file. Ideally, I would store data in arrays instead.
I was thinking something like:
int deleteRepeats(char *a)
{
int i;
for (i=0; i<=MAXCHARS; i++) {
if (a[i] != '\n')
/* copy into new array /*
}
}
but I'm somewhat lost. I don't want to print the array right now, because I will be altering it again later in my program; I still need to use a.
Any help/solution is greatly appreciated. Thank you.
Some guidance: