-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_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: tkiselev <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/03/21 16:31:27 by tkiselev #+# #+# */
/* Updated: 2018/03/28 19:16:12 by tkiselev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
size_t i;
size_t len;
char *new_str;
len = ft_strlen(s1);
new_str = (char *)malloc(sizeof(char) * (len + 1));
if (!new_str)
return (0);
i = 0;
while (i < len)
{
new_str[i] = (char)s1[i];
i++;
}
new_str[i] = s1[i];
return (new_str);
}