Hi,
My program removes the duplicate string(s) and outputs the unique strings but as soon as it does I get an error message saying stack around the variable buffer was corrupted?
Code:
#include<stdio.h>
#include <string.h>
int main(void)
{
char buffer[4][4]={"cat","mat","cat","hat"};
int i, j, k;
int a=4;
for (i = 0;i < a; i++)
{
for (j = i + 1; j < 4;)
{
if (strcmp(buffer[j],buffer[i])==0)
{
for (k = j; k < a; k++)
{
strcpy(buffer[k],buffer[k+1]);
}
a--;
}
else
j++;
}
}
for (i = 0; i < a; i++)
{
printf("%s", buffer[i]);
}
return (0);
}