-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
32 lines (29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: amennad <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/07 11:01:48 by amennad #+# #+# */
/* Updated: 2023/04/08 13:00:17 by amennad ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
char *ft_strdup(const char *s1)
{
int i;
char *copy;
i = 0;
copy = (char *) malloc(sizeof(char) *(ft_strlen(s1)) + 1);
if (!copy)
return (NULL);
while (i < (int)ft_strlen(s1))
{
copy[i] = s1[i];
i++;
}
copy[i] = '\0';
return (copy);
}