-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strsplit.c
More file actions
42 lines (39 loc) · 1.38 KB
/
ft_strsplit.c
File metadata and controls
42 lines (39 loc) · 1.38 KB
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
42
/* ************************************************************************** */
/* LE - / */
/* / */
/* ft_strsplit.c .:: .:/ . .:: */
/* +:+:+ +: +: +:+:+ */
/* By: rcabotia <marvin@le-101.fr> +:+ +: +: +:+ */
/* #+# #+ #+ #+# */
/* Created: 2018/10/08 11:07:22 by rcabotia #+# ## ## #+# */
/* Updated: 2018/10/08 16:52:55 by rcabotia ### #+. /#+ ###.fr */
/* / */
/* / */
/* ************************************************************************** */
#include "libft.h"
char **ft_strsplit(char const *s, char c)
{
char **str;
int length;
int i;
int j;
if (!s || !c)
return (NULL);
if (!(str = ft_memalloc(ft_strlen(s) + 1)))
return (NULL);
i = 0;
j = 0;
while (s[i])
if (s[i] == c)
i++;
else
{
length = 0;
while (s[i + length] && (s[i + length] != c))
length++;
str[j++] = ft_strsub(s, i, length);
i += length;
}
str[j] = NULL;
return (str);
}