-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup2.c
35 lines (32 loc) · 1.19 KB
/
ft_strdup2.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
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mavinici <mavinici@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/20 21:03:12 by mavinici #+# #+# */
/* Updated: 2022/04/21 09:31:22 by mavinici ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
char *ft_strdup2(const char *s)
{
char *new_str;
size_t len;
size_t i;
if (!s)
return (ft_strdup2(""));
len = ft_strlen(s);
new_str = (char *)malloc(len + 1);
if (new_str == NULL)
return (NULL);
i = 0;
while (i < len)
{
new_str[i] = s[i];
i++;
}
new_str[len] = '\0';
return (new_str);
}