Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
** EPITECH PROJECT, 2024 |
3 |
|
|
** my_list_to_array |
4 |
|
|
** File description: |
5 |
|
|
** Returns an array from a linked list |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#include "mylist.h" |
9 |
|
|
|
10 |
|
✗ |
void **my_list_to_array(linked_list_t *list) |
11 |
|
|
{ |
12 |
|
✗ |
int size = my_list_size(list); |
13 |
|
✗ |
void **array = malloc(sizeof(void *) * (size + 1)); |
14 |
|
✗ |
linked_list_t *tmp = list; |
15 |
|
|
|
16 |
|
✗ |
if (array == NULL) |
17 |
|
✗ |
return NULL; |
18 |
|
✗ |
for (int i = 0; tmp != NULL; i++) { |
19 |
|
✗ |
array[i] = tmp->data; |
20 |
|
✗ |
tmp = tmp->next; |
21 |
|
|
} |
22 |
|
✗ |
array[size] = NULL; |
23 |
|
✗ |
return array; |
24 |
|
|
} |
25 |
|
|
|