-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strsplit.c
41 lines (38 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkwayiba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/31 10:28:28 by jkwayiba #+# #+# */
/* Updated: 2019/06/21 09:32:10 by jkwayiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
size_t i;
size_t j;
size_t k;
char **w;
i = 0;
j = 0;
k = 0;
if (!s ||
(!(w = (char **)malloc(sizeof(char *) * (ft_wordcount(s, c) + 1)))))
return (NULL);
while (i < ft_wordcount(s, c))
{
j = 0;
while (s[k] == c)
k++;
while (s[k + j] != c && s[k + j])
j++;
w[i] = ft_strsub(s, k, j);
i++;
k += j;
}
w[i] = NULL;
return (w);
}