-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
32 lines (29 loc) · 1.12 KB
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: msaliuta <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/27 18:54:16 by msaliuta #+# #+# */
/* Updated: 2018/11/04 14:57:13 by msaliuta ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *cpy;
size_t i;
size_t n;
cpy = (char*)malloc(ft_strlen(s) + 1);
i = -1;
n = ft_strlen(s);
if (cpy)
{
while (++i < n)
cpy[i] = s[i];
cpy[i] = '\0';
return (cpy);
}
return (NULL);
}