-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_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: jkang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/26 22:29:32 by jkang #+# #+# */
/* Updated: 2020/04/10 12:52:55 by jkang ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
int len;
int i;
char *temp;
len = 0;
while (s[len] != '\0')
++len;
temp = (char *)malloc(sizeof(char) * (len + 1));
if (temp == 0)
return (0);
i = 0;
while (i < len)
{
temp[i] = s[i];
++i;
}
temp[i] = '\0';
return (temp);
}