-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strdup.c
40 lines (36 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: azaghlou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 13:08:46 by azaghlou #+# #+# */
/* Updated: 2022/10/18 14:38:47 by azaghlou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s1)
{
int i;
int j;
char *s2;
i = ft_strlen(s1);
j = 0;
s2 = malloc(sizeof(char) * i + 1);
if (s2 == NULL)
return (NULL);
while (s1[j] != '\0')
{
s2[j] = s1[j];
j++;
}
s2[j] = '\0';
return (s2);
}
// #include <stdio.h>
// int main()
// {
// printf("strdup :%s",strdup("44 m//47"));
// printf("\nft_strdup :%s",ft_strdup("44 m//47"));
// }