-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
40 lines (37 loc) · 1.2 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
40
/* ************************************************************************** */
/* */
/* :::::::: */
/* strdup.c :+: :+: */
/* +:+ */
/* By: ivan-mel <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/10/11 14:04:33 by ivan-mel #+# #+# */
/* Updated: 2022/10/14 19:21:06 by ivan-mel ######## odam.nl */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <stdlib.h>
char *ft_strdup(const char *s1)
{
char *s2;
int i;
i = 0;
while (s1[i] != '\0')
i++;
s2 = malloc(sizeof(char) * (i + 1));
if (s2 == NULL)
return (s2);
i = 0;
while (s1[i] != '\0')
{
s2[i] = s1[i];
i++;
}
s2[i] = '\0';
return (s2);
}
/*
int main(void)
{
ft_strdup("abcd");
}*/