-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_numofwords.c
41 lines (38 loc) · 1.23 KB
/
ft_numofwords.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_numofwords.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oltkache <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/09 12:53:38 by oltkache #+# #+# */
/* Updated: 2017/11/09 12:53:40 by oltkache ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_numofwords(char const *s, char c)
{
int i[4];
i[0] = 0;
i[2] = ft_strlen(s);
while (s[i[0]] == c)
++i[0];
while (s[i[2]] == c)
--i[2];
i[2] -= i[0];
i[0] = 0;
i[1] = 1;
while (i[0] < i[2])
{
i[3] = 0;
while (s[i[0]] == c)
{
if (i[3] == 0)
++i[1];
i[3] = 1;
++i[0];
}
++i[0];
}
return (i[1]);
}