-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
executable file
·31 lines (28 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chonorat <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/05 16:31:03 by chonorat #+# #+# */
/* Updated: 2022/12/05 16:31:04 by chonorat ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
unsigned int index;
char *malloc_s1;
malloc_s1 = (char *)malloc((ft_strlen(s1) + 1) * sizeof(char));
if (!malloc_s1)
return (NULL);
index = 0;
while (s1[index])
{
malloc_s1[index] = s1[index];
index++;
}
malloc_s1[index] = '\0';
return (malloc_s1);
}