-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
46 lines (41 loc) · 1.34 KB
/
Copy pathft_strdup.c
File metadata and controls
46 lines (41 loc) · 1.34 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ryusukeyashiro <ryusukeyashiro@student. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/23 14:09:06 by ryyashir #+# #+# */
/* Updated: 2024/04/28 12:56:44 by ryusukeyash ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
size_t i;
char *hold;
i = 0;
hold = (char *)malloc(sizeof(char) * (ft_strlen(s1) + 1));
if (!hold)
return (NULL);
while (s1[i])
{
hold[i] = s1[i];
i++;
}
hold[i] = '\0';
return (hold);
}
// #include <stdio.h>
// int main(int argc, char *argv[])
// {
// char *p;
// char *str;
// if (argc > 1)
// {
// str = argv[1];
// p = ft_strdup(str);
// printf("ft_strdup(p) = %s\n", p);
// free(p);
// }
// }