-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
36 lines (33 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amahla <amahla@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 12:34:30 by amahla #+# #+# */
/* Updated: 2022/05/03 09:59:36 by amahla ### ########.fr */
/* */
/* ************************************************************************** */
#include"libft.h"
char *ft_strdup(const char *s)
{
char *dst;
size_t i;
size_t size;
i = 0;
size = 0;
while (*(s + i++))
size++;
dst = malloc((size + 1) * sizeof(char));
if (!dst)
return (NULL);
i = 0;
while (i < size)
{
*(dst + i) = *(s + i);
i++;
}
*(dst + i) = '\0';
return (dst);
}