Bonjour,
Voila comme vous pouvez le voir dans le code ci dessous, à la ligne qui est commenté par "// ICI", je réinitialise hTmp à NULL, mais comment faire pour réinitialisé le pointeur que celui-çi pointe (c'est à dire htbl[key_hash]) à NULL tout en passant par hTmp (je suis claire ?)
Je pourais très bien faire
Mais par curiosité je veux juste passé par hTmp.
Code : Sélectionner tout - Visualiser dans une fenêtre à part htbl[key_hash] = NULL;
Merci !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 void hashtbl_erase(HTBL **htbl, char *key) { unsigned int key_hash; HTBL *hTmp, *hPrev; key_hash = hach_string(key); hTmp = htbl[key_hash]; hPrev = NULL; while(hTmp != NULL) { if (strcasecmp(hTmp->key, key) == 0) { if (hPrev != NULL) { hPrev->next = hTmp->next; } else { htbl[key_hash] = hTmp->next; } free(hTmp->key); hTmp->key = NULL; free(hTmp); hTmp = NULL; // ICI return; } hPrev = hTmp; hTmp = hTmp->next; } }
Partager