-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstiter.c
64 lines (59 loc) · 1.96 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jopedro3 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 11:57:33 by jopedro3 #+# #+# */
/* Updated: 2023/10/04 14:47:02 by jopedro3 ### ########.fr */
/* */
/* ************************************************************************** */
/*
Function: ft_lstiter
Purpose: Applies a function to the content of each element in a list.
How it works:
- Checks if 'lst' and 'f' are not NULL to proceed.
- Iterates through each element in the list.
- Applies function 'f' to the content of each element.
- Does not return anything.
- Note: The list navigation is done using 'lst = lst->next'.
*/
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}
/*#include <stdio.h>
void to_uppercase(void *content)
{
char *str;
str = (char *)content;
while (*str)
{
*str = ft_toupper(*str);
str++;
}
}
int main(void)
{
t_list *element;
char str[] = "hello";
element = ft_lstnew(str);
if (!element)
{
printf("Failed to create list element!\n");
return (1);
}
printf("Before: %s\n", (char *)element->content);
ft_lstiter(element, to_uppercase);
printf("After: %s\n", (char *)element->content);
free(element);
return (0);
}*/