-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
41 lines (37 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aerrajiy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 10:36:47 by aerrajiy #+# #+# */
/* Updated: 2022/10/13 18:47:31 by aerrajiy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *dup;
int len;
int i;
len = ft_strlen(s1);
dup = malloc((len +1) * sizeof(char));
if (dup == NULL)
return (dup = NULL);
i = 0;
while (i < len)
{
dup[i] = s1[i];
i++;
}
dup[i] = '\0';
return (dup);
}
/*
int main()
{
char str[] = "this is test";
printf("%d");
}
*/