-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
38 lines (34 loc) · 1.22 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
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aviholai <aviholai@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/08 13:18:36 by aviholai #+# #+# */
/* Updated: 2022/02/15 15:36:59 by aviholai ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** 'Strdup()' (String duplicate) copies and returns an applied string.
*/
char *ft_strdup(const char *src)
{
char *dest;
int i;
int i2;
i2 = 0;
while (src[i2])
i2++;
dest = (char *)malloc(sizeof(*dest) * (i2 + 1));
if (dest == NULL)
return (NULL);
i = 0;
while (i <= i2)
{
dest[i] = src[i];
i++;
}
return (dest);
}