ft_lstmap.c 1.2 KB

1234567891011121314151617181920212223242526272829
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* ft_lstmap.c :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: mazimi <mazimi@student.42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2014/12/10 15:38:49 by mazimi #+# #+# */
  9. /* Updated: 2014/12/11 16:13:50 by mazimi ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "../libft.h"
  13. t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
  14. {
  15. t_list *ret;
  16. if (lst != NULL)
  17. {
  18. ret = (t_list*)malloc(sizeof(f(lst)));
  19. if (ret == NULL)
  20. return (NULL);
  21. ret = f(lst);
  22. ret->next = ft_lstmap(lst->next, f);
  23. return (ret);
  24. }
  25. return (NULL);
  26. }