-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
39 lines (36 loc) · 1.17 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
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lwilliam <lwilliam@student.42kl.edu.my> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/26 10:15:13 by lwilliam #+# #+# */
/* Updated: 2022/05/30 11:21:39 by lwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include"libft.h"
char *ft_strdup(const char *s)
{
int x;
int len;
char *str;
x = 0;
len = 0;
while (s[x] != '\0')
{
len++;
x++;
}
str = malloc(sizeof(char) * (len + 1));
if (str == NULL)
return (NULL);
x = 0;
while (s[x])
{
str[x] = s[x];
x++;
}
str[x] = '\0';
return (str);
}