-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
33 lines (30 loc) · 1.14 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: mgraaf <mgraaf@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/12/16 14:24:00 by mgraaf #+# #+# */
/* Updated: 2021/12/16 14:24:02 by mgraaf ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *s2;
size_t size;
size_t i;
i = 0;
size = ft_strlen(s1);
s2 = (char *)malloc((size * sizeof(char)) + 1);
if (!s2)
return (0);
while (i < size)
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
return (s2);
}