I need help in removing duplicate strings. My code is almost there, it outputs the unique strings then crashes, see for yourself. How can I stop this from happening?
#include <stdio.h> #include <string.h> int main(void) { char array[4][4]={"cat","mat","sat","mat"}; int i, j, k; int a=4; for (i = 0;i < a; i++) { for (j = i + 1; j < 4;) { if (strcmp(array[j],array[i])==0) { for (k = j; k < a; k++) { strcpy(array[k],array[k+1]); } a--; } else j++; } } for (i = 0; i < a; i++) { printf("%s", array[i]); } return (0); }