-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_split.c
More file actions
56 lines (51 loc) · 1.46 KB
/
ft_split.c
File metadata and controls
56 lines (51 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kfouad < kfouad@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/10 15:36:13 by kfouad #+# #+# */
/* Updated: 2022/10/12 20:29:59 by kfouad ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int chhal_mn_klma(char *s, char c)
{
int i;
int j;
j = 0;
i = 0;
while (s[i] == c)
i++;
while (s[i])
{
if (s[i] == c && s[i + 1] != c && s[i + 1])
j++;
i++;
}
return (j + 1);
}
char **ft_split(char const *s, char c)
{
char **result;
int i;
int j;
int k;
i = 0;
k = 0;
result = malloc((chhal_mn_klma((char *)s, c) + 1) * sizeof(char *));
while (s[i])
{
while (s[i] == c && s[i])
i++;
j = i;
while (s[j] != c && s[j])
j++;
if (j != i)
result[k++] = ft_substr(s, i, j - i);
i = j;
}
result[k] = (char *) '\0';
return (result);
}