-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_ft_lstmap.c
61 lines (50 loc) · 1.42 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
#include "libft.h"
#include <stdlib.h>
t_list *some_function(t_list *elem)
{
char *sk;
t_list *ret;
ret = ft_lstnew(elem->content, elem->content_size);
sk = (char *)ret->content;
while (*sk)
{
*sk = ft_toupper(*sk);
sk++;
}
// ret->content_size *= 2;
return ret;
}
int main()
{
char *str;
t_list *a;
str = ft_strnew(5);
a = ft_lstnew(str, 5);
free(str);
((char *)a->content)[0] = 'a';
ft_putstr(">>> Initial list\n");
ft_print_list(a);
ft_putstr("----------------------------------------------------------------------\n");
str = ft_strnew(5);
a->next = ft_lstnew(str, 5);
free(str);
((char *)a->next->content)[0] = 'b';
ft_putstr(">>> List with one more chain\n");
ft_print_list(a);
ft_putstr("----------------------------------------------------------------------\n");
str = ft_strnew(5);
a->next->next = ft_lstnew(str, 5);
free(str);
((char *)a->next->next->content)[0] = 'c';
ft_putstr(">>> ...one more again\n");
ft_print_list(a);
ft_putstr("----------------------------------------------------------------------\n");
t_list *b = ft_lstmap(a, &some_function);
ft_putstr(">>> Initial list after map function\n");
ft_print_list(a);
ft_putstr("----------------------------------------------------------------------\n");
ft_putstr(">>> New list returned from map function\n");
ft_print_list(b);
ft_putstr("----------------------------------------------------------------------\n");
return 0;
}