-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
30 lines (27 loc) · 1.12 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: youkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/09 10:42:42 by youkim #+# #+# */
/* Updated: 2021/05/09 17:59:28 by youkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *ret;
size_t i;
size_t len;
len = ft_strlen(s1);
ret = malloc((len + 1) * sizeof(char));
if (!ret)
return (0);
ret[len] = 0;
i = -1;
while (++i < len)
ret[i] = s1[i];
return (ret);
}