-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsplit.c
39 lines (36 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssalaues <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/05 14:40:29 by ssalaues #+# #+# */
/* Updated: 2016/12/22 14:01:57 by ssalaues ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
char **str;
size_t nb;
size_t i;
i = 0;
if (!s || !c)
return (NULL);
nb = ft_wcount(s, c);
str = (char **)malloc(sizeof(*str) * (nb + 1));
if (!str)
return (NULL);
str[nb] = NULL;
while (nb > 0)
{
while (*s == c && *s)
s++;
str[i] = ft_strsub(s, 0, ft_wordlen(s, c));
s = s + ft_wordlen(s, c);
i++;
nb--;
}
return (str);
}