-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
47 lines (43 loc) · 1.48 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
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/17 12:52:01 by ibeliaie #+# #+# */
/* Updated: 2023/05/23 14:22:09 by ibeliaie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* create duplicate of string */
char *ft_strdup(const char *str)
{
int i;
char *dup;
int strlen;
i = 0;
strlen = ft_strlen (str);
dup = malloc(sizeof(char) * (strlen + 1));
if (!dup)
return (NULL);
while (str[i] != '\0')
{
dup[i] = str[i];
i++;
}
dup[i] = '\0';
return (dup);
}
// int main()
// {
// const char *str = "bonjour";
// char *duplicate = ft_strdup(str);
// if (duplicate != NULL)
// {
// printf("Original string: %s\n", str);
// printf("Duplicated string: %s\n", duplicate);
// free(duplicate);
// }
// return (0);
// }