-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrdup.c
34 lines (31 loc) · 1.15 KB
/
strdup.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: albarret <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/12 21:18:36 by albarret #+# #+# */
/* Updated: 2018/11/12 21:18:42 by albarret ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
char *new;
int i;
int size;
size = 0;
while (src[size])
size++;
if (!(new = malloc(sizeof(char) * (size + 1))))
return (NULL);
i = 0;
while (src[i])
{
new[i] = src[i];
i++;
}
new[i] = '\0';
return (new);
}