-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
35 lines (32 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: meltremb <meltremb@student.42quebec> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/30 18:12:49 by meltremb #+# #+# */
/* Updated: 2022/04/05 13:35:36 by meltremb ### ########.fr */
/* */
/* ************************************************************************** */
/* I wish i understood anything of how malloc works. would really be useful.
* Anyway that one seems to work somehow. make a string, allocate space equal
* to that gibberish and fill it with the given string. also set it to zero
* to make the moulinette happy. */
#include"libft.h"
char *ft_strdup(const char *s1)
{
char *ptr;
int i;
i = 0;
ptr = malloc((ft_strlen(s1) + 1) * (sizeof(char)));
if (!ptr)
return (NULL);
while (s1[i] != '\0')
{
ptr[i] = s1[i];
i++;
}
ptr[i] = '\0';
return (ptr);
}