-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strsplit.c
42 lines (39 loc) · 1.27 KB
/
ft_strsplit.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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fokrober <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/13 13:52:10 by fokrober #+# #+# */
/* Updated: 2019/04/23 19:51:12 by fokrober ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
char **tab;
size_t i;
size_t j;
if (!s)
return (0);
i = 0;
if (!(tab = ft_memalloc(sizeof(char*))))
return (NULL);
while (s[i])
{
while (s[i] && s[i] == c)
i++;
j = i;
while (s[i] && s[i] != c)
i++;
if (i > j)
{
tab = ft_push_str(tab, ft_strsub(s, j, (i - j)));
}
if (!s[i])
break ;
i++;
}
return (tab);
}