-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_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: ttran <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/05 16:59:40 by ttran #+# #+# */
/* Updated: 2017/12/07 19:05:20 by ttran ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
char **fuck;
int count;
int i;
int n;
n = 0;
i = 0;
if (s == 0)
return (NULL);
count = ft_nmbwrd((char *)s, c);
fuck = (char **)malloc(sizeof(char *) * (count + 1));
if (fuck == 0)
return (NULL);
while (s[i])
{
if (s[i] != c)
fuck[n++] = ft_mallocwrd((char *)s, i, c);
while (s[i] != c && s[i])
i++;
if (s[i] != '\0')
i++;
}
fuck[n] = 0;
return (fuck);
}