Bonjour a tous !
Voila j'ai un petit problème avec une liste chainée en static, je n'arrive pas a la free ^_^
La struct en question:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 typedef struct s_hist { char *cmd; int nb; int h; int m; struct s_hist *next; struct s_hist *prev; } t_hist;Les fonctions add_history et disp_history fonctionne bien mais quand je veut clear la list sa ne fonctionne pas.
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 void clear_history(t_hist **history) { t_hist *tmp; while (*history) { printf("Killing: %s\n", (*history)->cmd); tmp = (*history)->prev; free((*history)->cmd); free((*history)); (*history) = tmp; } (*history) = NULL; } void history(char *buff, int flag) { static t_hist *history = NULL; if (flag == 0 && buff) add_history(&history, buff); if (flag == 1) clear_history(&history); if (flag == 2) disp_history(history); }
je fait disp_history(history) --> la list s'affiche correctement.
j'appele clear_history(&history) --> il parcours bien toute la list
je raffiche, rien n'est effacer.
Partager