Salvar palavras distintas na lista encadeada
Basicamente eu tenho 2 lista ligada aqui: lista e distinta. Existem algumas palavras que foram salvas anteriormente na estrutura 'list'. Vai escrever um programa que vai encontrar as palavras que são distintas / únicas e salvá-lo na estrutura 'distinta'. Aqui está o que eu tenho até agora com base no meu conceito de ponteiros. No entanto, quando tento imprimir 'distinta', o programa trava :( por favor me corrija se eu estiver errado.
struct list {
char string[50];
struct list *next;
};
struct distinct {
char string[50];
struct distinct *next;
};
void checkdistinct() {
list *ori = NULL;
distinct *copy = NULL;
distinct *check = NULL;
if(ori == NULL && copy == NULL) { //first time.
ori = ori->next;
copy = copy->next;
copy = (distinct*)malloc(sizeof(distinct));
strcpy(copy->string, ori->string);
ori = ori->next;
copy = copy->next;
}
else {}
while(ori!=NULL) {
check = check->next;
while(check != NULL) {
if(strcmp(ori->string, check->string)!=0) {
check = check->next;
}
else {
ori = ori->next;
check = NULL;
}
}
//only compare same casing words, for now.
copy = (distinct*)malloc(sizeof(distinct));
strcpy(copy->string, ori->string);
ori = ori->next;
copy = copy->next;
}
}
Quando eu tento imprimir no main, ele irá falhar :( por favor, responda se você precisar de comentários extras para os códigos. Obrigado!