-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
31 lines (28 loc) · 1.13 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: selhilal <selhilal@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/18 16:00:29 by selhilal #+# #+# */
/* Updated: 2022/10/22 09:30:44 by selhilal ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *string)
{
int i;
char *ptr;
i = 0;
ptr = (char *)malloc(sizeof(char) * ft_strlen(string)+1);
if (!ptr)
return (NULL);
while (string[i])
{
ptr[i] = string[i];
i++;
}
ptr[i] = '\0';
return (ptr);
}