-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
50 lines (47 loc) · 1.51 KB
/
ft_strdup.c
File metadata and controls
50 lines (47 loc) · 1.51 KB
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
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgerdzhi <rgerdzhi@student.42barcelon +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/04 12:46:48 by rgerdzhi #+# #+# */
/* Updated: 2024/07/18 16:19:09 by rgerdzhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*The strdup() function returns a pointer to a new string which is a duplicate
of the string s. Memory for the new string is obtained with malloc(3), and can
be freed with free(3).*/
char *ft_strdup(const char *s)
{
size_t i;
size_t len;
char *d;
i = 0;
len = ft_strlen(s);
d = ft_calloc(len + 1, 1);
if (!d)
return (NULL);
while (i < len)
{
d[i] = s[i];
i++;
}
return (d);
}
/*
int main()
{
const char dst[] = "12334*6ybki0";
char *result;
char *mine;
result = strdup(dst);
printf("ctrl: %s\n", result);
mine = ft_strdup(dst);
printf("mine: %s\n", mine);
free(result);
free(mine);
return (0);
}
*/