-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
33 lines (30 loc) · 1.15 KB
/
Copy pathft_strdup.c
File metadata and controls
33 lines (30 loc) · 1.15 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: obouizi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/26 11:54:27 by obouizi #+# #+# */
/* Updated: 2024/11/04 18:31:15 by obouizi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
char *ptr;
size_t i;
size_t s_len;
i = 0;
s_len = ft_strlen(s1);
ptr = (char *) malloc(s_len + 1);
if (ptr == NULL)
return (NULL);
while (i < s_len)
{
ptr[i] = s1[i];
i++;
}
ptr[s_len] = '\0';
return (ptr);
}