-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstclear_bonus.c
87 lines (74 loc) · 2.42 KB
/
ft_lstclear_bonus.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edetoh <edetoh@student.42lehavre.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 16:01:22 by edetoh #+# #+# */
/* Updated: 2024/10/25 11:12:21 by edetoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
ft_lstclear deletes and frees all elements of 'lst'.
Takes 'lst' (address of pointer to start of list)
and 'del' (function to delete contents).
Returns nothing.
*/
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *temp;
if (!lst || !del)
return ;
while (*lst)
{
temp = (*lst)->next;
ft_lstdelone(*lst, del);
*lst = temp;
}
*lst = NULL;
}
// void delcontent(void *content)
// {
// free(content);
// }
// #include <stdio.h>
// #include <stdlib.h>
// #include "libft.h"
// int main(void)
// {
// t_list *node;
// char *content = ft_strdup("bonjour !");
// node = ft_lstnew(content);
// if (node)
// {
// printf("Node content: %s\n", (char *)node->content);
// printf("Node next bf add: %p\n", (void *)node->next);
// t_list *newbuble1;
// char *newbuble1_content = ft_strdup("coucou !");
// // Allouer de la mémoire pour newbuble1
// newbuble1 = ft_lstnew(newbuble1_content);
// if (newbuble1)
// {
// ft_lstadd_back(&node, newbuble1);
// printf(">> next cont aft add: %s\n", (char *)node->next->content);
// printf(">> next after add: %p\n", (void *)node->next);
// printf(">>>>> Taille : %i\n", ft_lstsize(node));
// printf(">>>>> Last : %s\n", (char *)ft_lstlast(node)->content);
// }
// else
// {
// printf("Failed to create newbuble1\n");
// }
// }
// else
// {
// printf("Failed to create node\n");
// }
// // Libérer la mémoire allouée
// if (node)
// ft_lstclear(&node, delcontent);
// printf(">>>>> Taille apres : %i\n", ft_lstsize(node));
// return 0;
// }