-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strcdup.c
35 lines (32 loc) · 1.2 KB
/
ft_strcdup.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: rabougue <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 21:53:58 by rabougue #+# #+# */
/* Updated: 2016/09/15 12:38:16 by rabougue ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/libft.h"
char *ft_strcdup(const char *s1, char c)
{
int i;
int j;
char *dst;
i = 0;
j = ft_strclen(s1, ' ');
dst = (char *)malloc(sizeof(char) * (j + 1));
if (dst == NULL)
return (NULL);
while (s1[i] != c)
{
if (s1[i] == '\0')
break ;
dst[i] = s1[i];
i++;
}
dst[i] = '\0';
return (dst);
}