-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
35 lines (32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nvienot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/12 17:39:58 by nvienot #+# #+# */
/* Updated: 2019/03/16 17:21:25 by nvienot ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strdup(const char *s1)
{
int i;
int len;
char *str;
len = 0;
i = 0;
while (s1[len])
len++;
if ((!(str = (char*)malloc(sizeof(char) * (len + 1)))))
return (NULL);
while (i < len)
{
str[i] = s1[i];
i++;
}
str[i] = '\0';
return (str);
}