-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
53 lines (47 loc) · 1.6 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kakiba <kotto555555@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/12 00:03:20 by kakiba #+# #+# */
/* Updated: 2022/12/22 21:35:56 by kakiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_lst;
t_list *buf;
if ((lst == NULL) || (f == NULL))
return (NULL);
new_lst = NULL;
while (lst)
{
buf = ft_lstnew(lst -> i, lst ->r, (f(lst -> content)));
if (buf == NULL)
{
ft_lstclear(&new_lst, del);
return (NULL);
}
ft_lstadd_back(&new_lst, buf);
lst = lst -> next;
}
return (new_lst);
}
/*
void *lstmap_f(void *content) {
(void)content;
return ("OK !");
}
int main()
{
t_list *l = ft_lstnew(strdup(" 1 2 3 "));
t_list *ret;
l->next = ft_lstnew(strdup("ss"));
l->next->next = ft_lstnew(strdup("-_-"));
ret = ft_lstmap(l, lstmap_f, NULL);
printf("%p\n", ret);
printf("%s\n", ret->content);
}*/