-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strsplit.c
41 lines (38 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
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmafa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/29 04:03:44 by nmafa #+# #+# */
/* Updated: 2019/07/08 18:46:02 by nmafa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
char **p;
size_t i;
size_t j;
size_t start;
if (!s)
return (0);
p = (char **)malloc(ft_strlen(s) * sizeof(p));
if (!p)
return (NULL);
i = 0;
j = 0;
while (i < ft_strlen(s))
{
while (s[i] != '\0' && s[i] == c)
i++;
start = i;
while (s[i] != '\0' && s[i] != c)
i++;
if (start < i)
p[j++] = ft_strsub(s, start, (i - start));
}
p[j] = 0;
return (p);
}