I am trying to take user input and print out each word on a separate line(without duplicates). What i have done so far is able to take user input and print each line separately in an alphabetical order. What i need to do right now is be able to remove the duplicates within the array that's char* argue[]
My Input:
./a.out banana apple apple apple zoo cat fork
My output:
apple
apple
apple
banana
cat
fork
zoo
what needs to be done is print one apple instead of three.
Here is what i have done so far and I have commented the part of code where the problem is
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[]) {
int i, j, k, size;
size = argc -1;
char *key;
char* a[argc-1];
for (i = 2; i < argc; i++) {
key = argv[i];
j = i-1;
while (j >= 1 && strcmp(argv[j], key) > 0) {
argv[j+1] = argv[j];
j--;
}
argv[j+1] = key;
}
//Problem
//for(i = 2; i < size; i++){
// if(argv[i-1] != argv[i])
// a[i] = argv[i-1];
//}
//for(i=0; i< size; i++)
// puts(a[i]);
for(i=1; i< argc; i++)
puts(argv[i]);
return 0;
}