-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
43 lines (38 loc) · 1.31 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
36
37
38
39
40
41
42
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysoroko <ysoroko@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/19 13:11:12 by ysoroko #+# #+# */
/* Updated: 2020/11/24 13:34:52 by ysoroko ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_strcpy(char *dest, const char *src)
{
int i;
char *my_src;
my_src = (char *)(src);
i = 0;
while (my_src[i] != '\0')
{
dest[i] = my_src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
char *ft_strdup(const char *src)
{
char *str;
char *my_src;
my_src = (char *)(src);
str = malloc(sizeof(*str) * (ft_strlen(my_src) + 1));
if (str == 0)
{
return (0);
}
return (ft_strcpy(str, my_src));
}