-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
35 lines (31 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jados-sa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/19 02:27:17 by jados-sa #+# #+# */
/* Updated: 2024/10/29 19:42:49 by jados-sa ### ########.fr */
/* */
/* ************************************************************************** */
/* Duplicate a string *
* Returns a pointer to a new string which is a duplicate of the string s. *
* Memory for the new string is obtained with malloc(), and can be freed with *
* free */
#include "libft.h"
char *ft_strdup(const char *s)
{
char *dup;
size_t i;
if (!s)
return (NULL);
dup = malloc(sizeof(char) * (ft_strlen(s) + 1));
if (!dup)
return (NULL);
i = 0;
while (*s)
dup[i++] = *s++;
dup[i] = '\0';
return (dup);
}