-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_findall.c
35 lines (32 loc) · 1.18 KB
/
ft_findall.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_findall.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yjouaoud <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 14:28:33 by yjouaoud #+# #+# */
/* Updated: 2019/04/12 15:31:33 by yjouaoud ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int *ft_findall(char *src, char c)
{
int i;
int j;
int count;
int *occ;
i = 0;
j = 0;
count = 0;
while (src[i])
if (src[i++] == c)
count++;
i = -1;
if (!(occ = (int*)malloc(sizeof(int) * count)))
return (0);
while (src[++i])
if (src[i] == c)
occ[j++] = i;
return (occ);
}