-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
37 lines (34 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atweek <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/07 20:22:58 by atweek #+# #+# */
/* Updated: 2020/11/08 04:35:18 by atweek ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
int size;
char *dst;
int i;
size = ft_strlen((char *)src) + 1;
dst = NULL;
dst = (char*)malloc(sizeof(char) * size);
if (dst)
{
i = 0;
while (src[i] != '\0')
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
i++;
}
((unsigned char *)dst)[i] = '\0';
}
else
return (NULL);
return (dst);
}