-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsplit.c
38 lines (35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: knzeng-e <knzeng-e@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/22 23:23:13 by knzeng-e #+# #+# */
/* Updated: 2016/04/01 03:26:59 by knzeng-e ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
int nb_words;
int j;
char **output;
char *str;
if (!(s))
return (NULL);
str = (char *)s;
nb_words = ft_count_words(s, c);
if (!(output = (char **)malloc(sizeof(char *) * nb_words + 1)))
return (NULL);
j = 0;
while (*str && *str == c)
str++;
while (j < nb_words)
{
ft_get_word(str, j, c, output);
j++;
}
output[j] = 0;
return (output);
}