-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_wordsplit.c
42 lines (39 loc) · 1.39 KB
/
ft_wordsplit.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
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_wordsplit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrophy <dbrophy@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/23 11:36:50 by dbrophy #+# #+# */
/* Updated: 2020/02/23 11:36:50 by dbrophy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "string.h"
int ft_wordsplit(char **arr, char *s, int maxcount)
{
int retval;
if (s == NULL || arr == NULL)
return (-1);
s = ft_strdup(s);
retval = 0;
while (*s)
{
if (*s != 0 && !ft_isspace(*s))
{
if (retval < maxcount - 1)
arr[retval] = s;
else if (retval == maxcount - 1)
arr[retval] = NULL;
retval++;
}
while (*s != 0 && !ft_isspace(*s))
s++;
while (ft_isspace(*s))
*(s++) = 0;
}
if (retval < maxcount - 1)
arr[retval] = NULL;
return (retval);
}