-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
45 lines (40 loc) · 1.32 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
41
42
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edegraev <edegraev@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 11:12:08 by edegraev #+# #+# */
/* Updated: 2023/11/16 09:20:14 by edegraev ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *str;
int i;
i = 0;
while (s[i])
i++;
str = (char *)malloc(sizeof(char) * (i + 1));
if (!str)
return (NULL);
i = 0;
while (s[i])
{
str[i] = s[i];
i++;
}
str[i] = '\0';
return (str);
}
// #include <stdio.h>
// int main()
// {
// const char *original = "The original string.";
// char *copy = ft_strdup(original);
// printf("%s\n", copy);
// free(copy);
// return 0;
// }