-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strsplit.c
41 lines (38 loc) · 1.32 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: luiroel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/19 11:59:09 by luiroel #+# #+# */
/* Updated: 2020/02/26 21:17:43 by luiroel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
int number;
char **str;
int i;
int j;
int start;
if ((s == 0) || (c == 0))
return (NULL);
number = ft_countwords(s, c);
str = malloc((sizeof(char *) * (number + 1)));
i = 0;
j = -1;
while (++j < number)
{
while (s[i] && s[i] == c)
i++;
start = i;
while (s[i] && s[i] != c)
i++;
str[j] = ft_strsub(s, start, i - start);
i++;
}
str[j] = NULL;
return (str);
}