ft_lstiter: initial implementation
This commit is contained in:
parent
47904658d0
commit
bece5aec9d
3 changed files with 49 additions and 2 deletions
45
ft_lstiter_bonus.c
Normal file
45
ft_lstiter_bonus.c
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter_bonus.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/21 16:54:35 by kcolin #+# #+# */
|
||||
/* Updated: 2024/10/21 16:59:43 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
while (lst != NULL)
|
||||
{
|
||||
(*f)(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void print_string(void *data)
|
||||
{
|
||||
printf("'%s'\n", (char *)data);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
t_list *list;
|
||||
t_list *new;
|
||||
|
||||
list = ft_lstnew("Hello There!");
|
||||
new = ft_lstnew("New Element!");
|
||||
ft_lstadd_front(&list, new);
|
||||
ft_lstiter(list, &print_string);
|
||||
ft_lstclear(&list, &print_string);
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue