-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strdup.c
35 lines (32 loc) · 1.15 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: eel-orch <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/19 00:52:28 by eel-orch #+# #+# */
/* Updated: 2019/11/10 01:19:37 by eel-orch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *s)
{
int j;
int index;
char *ptr;
index = 0;
j = -1;
while (s[index])
index++;
index++;
ptr = malloc(index * sizeof(char));
if (ptr)
{
while (s[++j])
ptr[j] = s[j];
ptr[j] = '\0';
return (ptr);
}
return (NULL);
}