-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_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: achambon <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/25 14:00:19 by achambon #+# #+# */
/* Updated: 2017/01/05 17:30:29 by achambon ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <string.h>
#include <stdlib.h>
char *ft_strdup(const char *s1)
{
int i;
int j;
char *dup;
i = ft_strlen(s1);
dup = (char*)malloc(sizeof(char) * (i + 1));
if (dup == NULL)
return (NULL);
j = 0;
while (j < i)
{
dup[j] = s1[j];
j++;
}
dup[j] = '\0';
return (dup);
}