-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
41 lines (38 loc) · 1.27 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: thuy-ngu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 21:22:25 by thuy-ngu #+# #+# */
/* Updated: 2023/10/14 17:58:35 by thuy-ngu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
size_t len;
char *dest;
int i;
len = ft_strlen(src);
dest = (char *)malloc((sizeof(char)) * (len) + 1);
if (!dest)
{
return (NULL);
}
i = 0;
while (src[i] != '\0')
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
/*int main(void)
{
char *dup = ft_strdup("It is something");
printf("%s\n", dup);
free(dup);
}*/