You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

41 lines
1.3 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dlst_to_arr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/24 10:50:10 by narnaud #+# #+# */
/* Updated: 2022/03/24 11:33:57 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "../libft.h"
char **ft_dlst_to_arr(t_dlist *ptr)
{
char **ret;
t_dlist *last;
t_dlist *tmp;
size_t count;
last = ptr;
count = 1;
if (!ptr)
return (ft_calloc(1, sizeof(char *)));
while (ptr->previous)
{
ptr = ptr->previous;
count++;
}
ret = ft_calloc(count + 1, sizeof(char *));
ret[count] = NULL;
while (count--)
{
ret[count] = last->content;
tmp = last;
free(last);
last = tmp->previous;
}
return (ret);
}