-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_realloc.c
39 lines (36 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thifranc <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/04/30 11:06:28 by thifranc #+# #+# */
/* Updated: 2016/04/30 11:07:11 by thifranc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_realloc(char **var, int add, int del)
{
int i;
char **new;
i = 0;
while (var[i])
i++;
if (!(new = (char**)malloc(sizeof(char*) * (i + 1 + add))))
return (NULL);
i = 0;
while (var[i])
{
new[i] = ft_strdup(var[i]);
if (del)
ft_memdel((void**)&var[i]);
i++;
}
if (del)
ft_memdel((void**)&var[i]);
new[i] = NULL;
while (add)
new[i + add--] = NULL;
return (new);
}