-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
executable file
·35 lines (32 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
34
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aemebiku <aemebiku@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/06/26 15:40:39 by aemebiku #+# #+# */
/* Updated: 2014/06/26 15:40:40 by aemebiku ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strdup(const char *s1)
{
char *str;
int i;
i = 0;
if (s1 == NULL)
return (NULL);
while (s1[i])
i++;
if ((str = (char *)malloc(sizeof(*str) * i + 1)) == NULL)
return (NULL);
i = 0;
while (s1[i] != '\0')
{
str[i] = s1[i];
i++;
}
str[i] = '\0';
return (str);
}