-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_split_cheaty.c
56 lines (52 loc) · 1.53 KB
/
ft_split_cheaty.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: polmarti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 11:25:52 by polmarti #+# #+# */
/* Updated: 2023/11/27 11:32:21 by polmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stdio.h>
char **ft_split(char *str)
{
int i;
int i2;
int i3;
char **tab;
i = 0;
i2 = 0;
tab = malloc(sizeof(char) * 1000);
while (str[i])
{
if (str[i] != ' ' && str[i] != '\t' && str[i] != '\n')
{
i3 = 0;
tab[i2] = malloc(sizeof(char) * 1000);
while (str[i] != ' ' && str[i] != '\t' && str[i] != '\n')
{
tab[i2][i3] = str[i];
i++;
i3++;
}
tab[i2][i3] = '\0';
i2++;
}
else
i++;
}
tab[i2] = 0;
return (tab);
}
int main(void)
{
char *str = "hola como estas";
char **result = ft_split(str);
printf("%s\n", result[0]);
printf("%s\n", result[1]);
printf("%s\n", result[2]);
return (0);
}