-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
35 lines (32 loc) · 1.18 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
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vess <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/14 17:52:42 by vess #+# #+# */
/* Updated: 2021/11/24 20:44:42 by vess ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strdup(const char *str)
{
int i;
char *cpy;
int len;
i = 0;
cpy = 0;
len = ft_strlen((char *)str);
cpy = (char *)malloc (sizeof(*cpy) * (len + 1));
if (!cpy)
return (NULL);
while (i < len)
{
cpy[i] = str[i];
i++;
}
cpy[i] = 0;
return (cpy);
}