-
Notifications
You must be signed in to change notification settings - Fork 2
/
ft_strdup.c
33 lines (30 loc) · 1.17 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: dzui <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/22 12:40:25 by dzui #+# #+# */
/* Updated: 2016/11/22 12:52:33 by dzui ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *duplicate;
int len;
int i;
len = ft_strlen(s);
duplicate = (char *)malloc(sizeof(char) * len + 1);
if (!duplicate)
return (NULL);
i = 0;
while (i < len)
{
duplicate[i] = s[i];
i++;
}
duplicate[i] = '\0';
return (duplicate);
}