-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstclear.c
48 lines (42 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akdemir <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/09 20:41:41 by akdemir #+# #+# */
/* Updated: 2023/07/19 16:02:48 by akdemir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *start;
t_list *tmp;
if (!del)
return ;
start = *lst;
while (start)
{
tmp = start;
del(tmp->content);
start = start -> next;
free(tmp);
}
*lst = NULL;
}
void del(void *cnt)
{
free(cnt);
}
int main()
{
t_list **a;
t_list *lst;
a = &lst;
lst = ft_lstnew("content1");
ft_lstclear(a, del);
printf("%s",lst->content);
return (0);
}