-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
33 lines (30 loc) · 1.15 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
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggladkov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/27 18:21:48 by ggladkov #+# #+# */
/* Updated: 2017/04/23 11:42:46 by ggladkov ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *s2;
size_t i;
size_t size;
size = ft_strlen(s1);
i = 0;
s2 = (char*)malloc(sizeof(char) * (size + 1));
if (s2 == NULL)
return NULL;
while (i < size)
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
return (&s2[0]);
}