-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
33 lines (30 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: melkholy <melkholy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/02 10:26:20 by melkholy #+# #+# */
/* Updated: 2022/02/08 05:43:44 by melkholy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *str)
{
char *dup;
size_t count;
size_t len;
len = ft_strlen(str);
dup = (char *)malloc((len + 1) * sizeof(char));
if (dup == NULL)
return (NULL);
count = 0;
while (count < len)
{
dup[count] = str[count];
count ++;
}
dup[count] = '\0';
return (dup);
}