-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsplit.c
40 lines (37 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hkchikec <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 18:50:02 by hkchikec #+# #+# */
/* Updated: 2019/05/02 14:53:15 by hkchikec ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
char **tab;
int i;
int start;
int j;
int wd;
wd = ft_count_words((char *)s, c);
i = 0;
j = 0;
tab = (char **)malloc(sizeof(char *) * (wd + 1));
if (tab == NULL)
return (NULL);
while (j < wd)
{
while (s[i] == c)
i++;
start = i;
while (s[i] != c && s[i] != '\0')
i++;
tab[j++] = ft_strsub((char *)s, start, (i - start));
}
tab[j] = NULL;
return (tab);
}