-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstmap.c
57 lines (50 loc) · 1.47 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
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akdemir <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/09 20:41:48 by akdemir #+# #+# */
/* Updated: 2023/07/17 13:53:46 by akdemir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_list;
t_list *tmp;
if (!lst)
return (NULL);
new_list = NULL;
while (lst)
{
tmp = ft_lstnew(f(lst->content));
if (!tmp)
{
ft_lstclear(&new_list, del);
printf("%s","zort");
return (NULL);
}
lst = lst->next;
ft_lstadd_back(&new_list, tmp);
}
return (new_list);
}
void *f(void *cnt)
{
cnt = "zart";
return (cnt);
}
void del(void *cnt)
{
free(cnt);
}
int main()
{
t_list *lst;
lst = ft_lstnew("");
lst = ft_lstmap(lst, f, del);
printf("%s",lst->content);
return (0);
}