pointers - Removing duplicates in linked list in C doesn't work -
so i'm trying remove duplicates linked list , code doesn't work. input list of words, , print same list before , after "removing". please
typedef struct node { char data[50]; struct node *next; } *list; void removeduplicate(list words){ list o = null, t = null, d = null; o = words; while(o != null && o->next != null){ t = o; while(t->next != null){ if(o->data == t->next->data){ d = t->next; t->next = d->next->next; free(d); } else{ t = t->next; } } o = o->next; } }
you can't if(o->data == t->next->data)
pointers starting location of char array , different. try using strcmp()
.
Comments
Post a Comment