Commit 29f997d4 authored by William Sha's avatar William Sha
Browse files

Minor fix for remove still in bug

parent bb79e679
......@@ -68,7 +68,7 @@ int main()
break;
case TOKEN_DEL_NB_SPC:
remove_element(NULL, 0);
remove_element(default_list, 2);
break;
case TOKEN_SRT_LI_ASC:
......
......@@ -109,7 +109,7 @@ int insert_after_position(List* list, char* str, int p){
int remove_element(List* list, int p){
if (DEBUG) printf("REMOVE_ELEMENT\n");
if (!*list){
if (!list){
printf("List pointer is null.\n");
return -1;
}
......@@ -120,13 +120,18 @@ int remove_element(List* list, int p){
}
int n = 1; // position du parcours
Element* e = list->head, suppr;
Element* e = list->head;
Element* suppr;
if (DEBUG) printf("FLAG 1\n");
/*
e sera utilisé pour pointer la bonne position, suppr sera utilisé pour "manger le nombre" (désallocation)
e will be used to focus on the right place, suppr will be used to "eat the number"
*/
while(n < p){ // tant que l'on est pas arrivé au Pème chiffre
if (DEBUG) printf("WHILE\n");
do{
e = e->next;
}while(e->data != NULL); // on parcoure la liste jusqu'au prochain nombre
......@@ -142,6 +147,7 @@ int remove_element(List* list, int p){
*/
do{
if (DEBUG) printf("DO2\n");
e->next = suppr->next;
free(suppr->data);
free(suppr);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment