-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstiter.c
103 lines (91 loc) · 2.37 KB
/
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmattera <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/21 13:34:05 by nmattera #+# #+# */
/* Updated: 2022/05/23 11:43:07 by nmattera ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!f)
return ;
while (lst)
{
(*f)(lst->content);
lst = lst->next;
}
}
/******************************************************************************/
/* #include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
void ft_modify_list_with_d(void *elem)
{
int len;
char *content;
len = 0;
content = (char *)elem;
while (content[len])
{
content[len++] = 'd';
}
}
void ft_print_result(t_list *elem)
{
int len;
while (elem)
{
len = 0;
while (((char *)elem->content)[len])
len++;
write(1, elem->content, len);
write(1, "\n", 1);
elem = elem->next;
}
}
t_list *ft_lstnewone(void *content)
{
t_list *elem;
elem = (t_list *)malloc(sizeof(t_list));
if (!elem)
return (NULL);
if (!content)
elem->content = NULL;
else
elem->content = content;
elem->next = NULL;
return (elem);
}
int main(int argc, const char *argv[])
{
t_list *elem;
t_list *elem2;
t_list *elem3;
t_list *elem4;
char *str = strdup("lorem");
char *str2 = strdup("ipsum");
char *str3 = strdup("dolor");
char *str4 = strdup("sit");
elem = ft_lstnewone(str);
elem2 = ft_lstnewone(str2);
elem3 = ft_lstnewone(str3);
elem4 = ft_lstnewone(str4);
alarm(5);
if (argc == 1 || !elem || !elem2 || !elem3 || !elem4)
return (0);
elem->next = elem2;
elem2->next = elem3;
elem3->next = elem4;
if (atoi(argv[1]) == 1)
{
ft_lstiter(elem, &ft_modify_list_with_d);
ft_print_result(elem);
}
return (0);
} */