-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_wordcount.c
34 lines (32 loc) · 1.11 KB
/
ft_wordcount.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_wordcount.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dnichol <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/11 13:34:25 by dnichol #+# #+# */
/* Updated: 2019/09/11 13:37:45 by dnichol ### ########.fr */
/* */
/* ************************************************************************** */
int ft_wordcount(char const *str, char c)
{
int i;
int j;
i = 0;
j = 0;
while (str[i] != '\0')
{
if (str[i] == c)
i++;
else
{
j++;
while (str[i] != c && str[i])
i++;
}
}
if (j == 0)
j = -1;
return (j + 1);
}