-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
50 lines (41 loc) · 1.37 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/18 12:46:26 by julmuntz #+# #+# */
/* Updated: 2022/05/19 16:21:24 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *d;
char *t;
d = malloc(ft_strlen(s) + 1 * sizeof(char));
if (d == NULL)
return (NULL);
t = d;
while (*s)
*t++ = *s++;
*t = 0;
return (d);
}
/*
#include <stdio.h>
#include <string.h>
int main(void)
{
char *src = "Hello";
char *dst;
puts("\n- strdup");
dst = strdup(src);
printf("%s\n", dst);
puts("\n- ft_strdup");
dst = ft_strdup(src);
printf("%s\n", dst);
return 0;
}
*/