-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear.c
59 lines (53 loc) · 1.61 KB
/
ft_lstclear.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tiagalex <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/11 16:29:31 by tiagalex #+# #+# */
/* Updated: 2024/11/12 14:13:21 by tiagalex ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//apaga toda a struct
void ft_lstclear(t_list **lst, void (*del)(void *))
{
t_list *current;
t_list *clone;
current = *lst;
if (!lst || !del)
return ;
while (current != NULL)
{
clone = current->next;
(*del)(current->content);
free(current);
current = clone;
}
*lst = NULL;
}
/*
void del(void *lst)
{
free(lst);
}
int main()
{
t_list *lst = ft_lstnew(ft_strdup("uva\n"));
ft_lstadd_back(&lst,ft_lstnew(ft_strdup("manga\n")));
ft_lstadd_back(&lst,ft_lstnew(ft_strdup("ananas\n")));
t_list *temp = lst;
t_list *temp1 = lst;
while (temp != NULL)
{
printf ("temp %s", (char *)temp->content);
temp = temp->next;
}
ft_lstclear(&lst, &del);
if (lst == NULL)
{
printf ("success!\n");
}
return (0);
} */