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