-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
34 lines (31 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qrobert- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/07 11:45:30 by qrobert- #+# #+# */
/* Updated: 2017/11/07 11:49:38 by qrobert- ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strdup(char *src)
{
int i;
char *temp;
i = 0;
while (src[i] != '\0')
i++;
temp = (char*)malloc(sizeof(*temp) * (i + 1));
if (temp == 0)
return (0);
i = 0;
while (src[i] != '\0')
{
temp[i] = src[i];
i++;
}
temp[i] = '\0';
return (temp);
}