-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
36 lines (33 loc) · 1.15 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: fgata-va <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/08 15:59:15 by fgata-va #+# #+# */
/* Updated: 2021/03/04 19:19:36 by fgata-va ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *s2;
size_t l;
unsigned int i;
i = 0;
l = ft_strlen(s1);
s2 = (char *)malloc(l + 1);
if (s2)
{
while (s1[i] != '\0' && i < l)
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
}
else
return (0);
return (s2);
}