-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_ft_lstiter.c
60 lines (55 loc) · 1.76 KB
/
test_ft_lstiter.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jliew <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/06 19:46:33 by jliew #+# #+# */
/* Updated: 2020/07/09 23:19:59 by jliew ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <string.h>
#include "libft.h"
void print_list(t_list *list)
{
while (list)
{
printf("[%s]", list->content);
printf("%s", ((list->next) ? " -> " : "\n"));
list = list->next;
}
}
void func(void *content)
{
free(content);
content = strdup("42");
}
int main(int argc, char **argv)
{
int i;
t_list *list;
if (argc == 1)
{
printf("-------------------------------------------------\n");
printf(" void ft_lstiter(t_list *lst, void (*f)(void *))\n");
printf("-------------------------------------------------\n");
printf("usage [manual]:\n");
printf("1. a --run\n");
return (42);
}
else if (!strcmp(argv[1], "--run"))
{
list = NULL;
i = 1;
while (i <= 10)
ft_lstadd_back(&list, ft_lstnew(ft_itoa(i++)));
printf("before: ");
print_list(list);
ft_lstiter(list, func);
printf("after: ");
print_list(list);
ft_lstclear(&list, free);
}
}