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