-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_realloc.c
42 lines (37 loc) · 1.27 KB
/
ft_realloc.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
32
33
34
35
36
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abkssiba <abkssiba@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/07 13:35:09 by abkssiba #+# #+# */
/* Updated: 2021/05/24 16:40:24 by abkssiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int arr_count(char **arr)
{
int i;
i = 0;
while (arr[i])
i++;
return (i);
}
char **ft_realloc(char **arr, char *line)
{
char **newarr;
int count;
int i;
i = 0;
count = arr_count(arr);
newarr = malloc((count + 2) * sizeof(char *));
while (i < count)
{
newarr[i] = ft_strdup(arr[i]);
i++;
}
newarr[i] = ft_strdup(line);
newarr[i + 1] = NULL;
return (newarr);
}