void del_x(LIST** head, int x) { if ((*head)->val == x) { del_first(&(*head)); } else { LIST* t = *head; LIST* q; while (t->val != x && t->next != NULL) { q = t; t = t->next; } if (t->val == x) { q->next = t->next; free(t); } } }
void pseudo_cmd() { FILE* f; f = fopen("input.dat", "r"); FILE* g; g = fopen("output.dat", "a"); LIST* head = NULL; char com[15]; char subcom[15]; int x = 0; while (!feof(f)) { fscanf(f, " %[^\n]s", com); // fprintf(g, "%d \n", list_length(head)); // print_all(head, g); // fprintf(g, "///////\n"); // fprintf(g, "%s\n", com); sscanf(com, "%s %d", subcom, &x); if (!strcmp(subcom, "AF")) add_first(&head, x); else if (!strcmp(subcom, "AL")) add_last(&head, x); else if (!strcmp(subcom, "DF")) del_first(&head); else if (!strcmp(subcom, "DL")) del_last(&head); else if (!strcmp(subcom, "DOOM_THE_LIST")) doom_the_list(&head); else if (!strcmp(subcom, "DE")) del_x(&head, x); else if (!strcmp(subcom, "PRINT_ALL")) print_all(head, g); else if (!strcmp(subcom, "PRINT_F")) print_first_n(head, x, g); else if (!strcmp(subcom, "PRINT_L")) print_last_n(head, x, g); } doom_the_list(&head); }
static int del_env(t_duo **env, char *name) { t_duo *cpy; t_duo *tmp; if (del_first(env, name) == 1) return (1); cpy = *env; tmp = NULL; while (cpy && cpy->next) { if (ft_strcmp(name, cpy->next->name) == 0) { tmp = cpy->next->next; ft_strdel(&(cpy->next->name)); ft_strdel(&(cpy->next->value)); free(cpy->next); cpy->next = tmp; return (1); } cpy = cpy->next; } return (-1); }