-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
33 lines (30 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ctokuyos <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 12:00:56 by ctokuyos #+# #+# */
/* Updated: 2024/11/06 16:32:51 by ctokuyos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *strcp;
size_t len;
size_t i;
i = 0;
len = ft_strlen(s);
strcp = (char *)malloc((len + 1) * sizeof(char));
if (!strcp)
return (NULL);
while (s[i] != '\0')
{
strcp[i] = s[i];
i++;
}
strcp[i] = '\0';
return (strcp);
}