-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_get_word.c
41 lines (38 loc) · 1.35 KB
/
ft_get_word.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_get_word.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: knzeng-e <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/26 21:43:37 by knzeng-e #+# #+# */
/* Updated: 2016/03/26 21:47:19 by knzeng-e ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_get_word(char const *str, int index, char c, char **out)
{
int i;
int cpt;
int deb;
i = 0;
cpt = 0;
while (cpt != index)
{
while (str[i] && str[i] != c)
i++;
while (str[i] && str[i] == c)
i++;
cpt = cpt + 1;
}
while (str[i] && str[i] == c)
i++;
deb = i;
cpt = 0;
while (str[i] && str[i] != c)
i++;
out[index] = (char *)malloc(sizeof(char) * (i - deb) + 1);
while (deb < i)
out[index][cpt++] = str[deb++];
out[index][cpt] = '\0';
}