-
Notifications
You must be signed in to change notification settings - Fork 10
/
ft_strdup.c
35 lines (31 loc) · 1.2 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: jaeskim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/26 12:13:28 by jaeskim #+# #+# */
/* Updated: 2020/09/27 02:40:41 by jaeskim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** ft_strdup - duplicate a string
*/
char *ft_strdup(const char *s)
{
size_t slen;
char *result;
slen = ft_strlen(s);
if (!(result = (char *)malloc(sizeof(char) * (slen + 1))))
return (0);
slen = 0;
while (s[slen])
{
result[slen] = s[slen];
slen++;
}
result[slen] = '\0';
return (result);
}