-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strpop.c
41 lines (38 loc) · 1.25 KB
/
ft_strpop.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
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strpop.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kacoulib <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/11 04:19:01 by kacoulib #+# #+# */
/* Updated: 2017/01/11 13:30:40 by kacoulib ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strpop(char **s, char c)
{
int i;
int j;
char *r;
if (!*s)
return (NULL);
if ((i = ft_indexof(*s, c)) < 0)
{
r = ft_strdup(*s);
*s = NULL;
return (r);
}
else if (i == 0)
{
(*s)++;
return (ft_strpop(s, c));
}
if (!(r = ft_memalloc(i)))
return (NULL);
j = -1;
ft_strncpy(r, *s, i);
while (++j < i && (**s))
(*s)++;
return (r);
}