-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_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: ybouzgao <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/06 20:37:03 by ybouzgao #+# #+# */
/* Updated: 2017/11/10 18:30:10 by ybouzgao ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strdup(const char *s1)
{
int len;
char *str;
len = 0;
while (s1[len])
len++;
if ((str = (char *)malloc(sizeof(*s1) * (len + 1))) == 0)
return (0);
len = 0;
while (s1[len])
{
str[len] = s1[len];
len++;
}
str[len] = '\0';
return (str);
}