Я пытаюсь вставить строку в связанный список других строк. Цель состоит в том, чтобы пользователь ввел любую желаемую строку (str_insert). Затем пользователь должен ввести, после какого слова он хочет вставить строку (new_node).
К сожалению, коду удается вставить слово, но он всегда вставляет его только на второй позиции. Функция, используемая для вставки слова, называется вставкой.
typedef struct dll {
char data;
int count;
struct dll* next;
} dll;
typedef struct dictionary {
dll * data;
struct dictionary* next;``
struct dictionary* prev;
} dictionary;
dll* entry(){
char data = getc(stdin);
if (data != '\n'){
dll* curr = create_dico(data);
curr->next=entry();
return curr;
}
return NULL;
}
dictionary* insertion(dictionary *dico) {
printf("Please enter the string you want to insert in your already
existing list: \n");
dictionary * str_insert = malloc(sizeof(dictionary));
str_insert->data = entry();
str_insert->next = NULL;
printf("Please enter after which word you would like to insert the
previous entry: \n");
dictionary* new_node =(dictionary*)malloc(sizeof(dictionary));
new_node->data = entry();
new_node->next = dico->next;
new_node->prev = dico;
if (dico->next != NULL) {
str_insert->next = dico->next;
dico->next = str_insert;
}
}