-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_split2.c
More file actions
91 lines (77 loc) · 1.13 KB
/
ft_split2.c
File metadata and controls
91 lines (77 loc) · 1.13 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
char *ft_strcpy(char *des, const char *src)
{
int i;
i = 0;
while (src[i])
{
des[i] = src[i];
i++;
}
des[i] = '\0';
return (des);
}
int wordcount(char *str, char c)
{
int i;
int words;
i = 0;
words = 0;
while (str[i] != '\0')
{
if (str[i] != c)
{
words++;
while (str[i] != c && str[i] != '\0')
i++;
}
while (str[i] == c)
i++;
}
return (words);
}
#include <stdlib.h>
char* ft_allocWord(char* str, char c)
{
(void)str;
(void)delimiter;
//aloue et copie le mot et le retourne
return (NULL);
}
char** ft_freetab(char **tab)
{
// loop de free de tableau
return (NULL);
}
char **ft_split(char *str, char c)
{
char **tab;
int i;
int words;
int iword;
if (!str)
return (NULL);
words = wordcount(str, c);
tab = (char**)malloc(sizeof(char*) * (words + 1));
i = 0;
iword = 0;
while (str[i])
{
if (str[i] != c)
{
tab[iword] = ft_allocWord(str + i, c);
if (tab[iword] == NULL)
return (ft_freetab(tab));
iword++;
while (str[i] && str[i] != c)
i++;
}
else
i++;
}
return (tab);
}
int main()
{
printf("%d\n", wordcount("", ' '));
return 0;
}