-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_dup_and_free.c
31 lines (28 loc) · 1.34 KB
/
ft_dup_and_free.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dup_and_free.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nfaust <nfaust@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/04 15:35:40 by nfaust #+# #+# */
/* Updated: 2023/03/06 15:05:15 by nfaust ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_dup_and_free(char **two_dim_array, size_t index)
{
char *save_element;
size_t max_index;
if (!two_dim_array)
return (NULL);
max_index = 0;
while (two_dim_array[max_index])
max_index++;
if (index >= max_index)
return (ft_free_twodimarr(two_dim_array), NULL);
save_element = ft_strdup(two_dim_array[index]);
if (!save_element)
return (ft_free_twodimarr(two_dim_array), NULL);
return (ft_free_twodimarr(two_dim_array), save_element);
}