-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strdup.c
More file actions
39 lines (35 loc) · 1.34 KB
/
ft_strdup.c
File metadata and controls
39 lines (35 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: antandre <antandre@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 11:04:24 by antandre #+# #+# */
/* Updated: 2024/05/22 11:50:43 by antandre ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include <stdlib.h>
#include "libft.h"
/*
* Returns a pointer to a new string that is a duplicate
* of the string pointed to by s. Memory for the new string is allocated
* automatically using malloc().
*/
char *ft_strdup(const char *s)
{
char *copy;
size_t i;
copy = (char *)malloc((ft_strlen(s) + 1) * sizeof(char));
if (copy == NULL)
return (NULL);
i = 0;
while (s[i] != '\0')
{
copy[i] = s[i];
i++;
}
copy[i] = '\0';
return (copy);
}