-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
36 lines (33 loc) · 1.16 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
36
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hezzahir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/07 15:33:16 by hezzahir #+# #+# */
/* Updated: 2018/11/08 17:45:52 by hezzahir ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *str)
{
char *cn;
char *ch;
int i;
cn = (char *)str;
i = 0;
ch = (char*)malloc((ft_strlen(cn) + 1) * sizeof(char));
if (!ch)
{
ch = NULL;
return (ch);
}
while (cn[i] != '\0')
{
ch[i] = cn[i];
i++;
}
ch[i] = '\0';
return (ch);
}