-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
33 lines (30 loc) · 1.16 KB
/
ft_strdup.c
File metadata and controls
33 lines (30 loc) · 1.16 KB
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: ivork <ivork@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2020/11/08 21:10:54 by ivork #+# #+# */
/* Updated: 2020/11/08 21:25:43 by ivork ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *str)
{
char *target;
int len;
int i;
i = 0;
len = ft_strlen(str);
target = malloc(sizeof(*str) * len + 1);
if (target == 0)
return (NULL);
while (str[i] != 0)
{
target[i] = str[i];
i++;
}
target[i] = '\0';
return (target);
}