-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
35 lines (32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kotainou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 19:05:42 by kotainou #+# #+# */
/* Updated: 2023/05/25 08:27:36 by kotainou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *ans;
int size;
int index;
index = 0;
if (s1 == NULL)
return (NULL);
size = ft_strlen(s1);
ans = (char *)malloc(sizeof(char) * (size + 1));
if (ans == NULL)
return (NULL);
while (s1[index])
{
ans[index] = s1[index];
index++;
}
ans[index] = 0;
return (ans);
}