-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
43 lines (35 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tauer <tauer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:39:38 by tauer #+# #+# */
/* Updated: 2023/11/06 15:39:38 by tauer ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
size_t len_s;
char *str;
char *ptr;
len_s = ft_strlen(s);
str = (char *)malloc(sizeof(char) * (len_s + 1));
if (!str)
return (NULL);
ptr = str;
while (len_s-- > 0)
*str++ = *s++;
*str = '\0';
return (ptr);
}
// int main(void)
// {
// char *test = "phrase tester";
// char *result = ft_strdup(test);
// printf("%s\n", result);
// free(result);
// return (0);
// }