-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
34 lines (31 loc) · 1.14 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
34
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuske <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/24 16:57:13 by yfurutat #+# #+# */
/* Updated: 2022/11/20 00:57:06 by yuske ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//16L
char *ft_strdup(const char *str)
{
char *dup;
size_t end;
size_t i;
i = 0;
end = ft_strlen(str);
dup = (char *)malloc(end + 1);
if (!dup)
return (NULL);
while (i < end)
{
dup[i] = str[i];
i++;
}
dup[i] = '\0';
return (dup);
}