-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_wordcountx.c
47 lines (42 loc) · 1.3 KB
/
ft_wordcountx.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
42
43
44
45
46
47
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_wordcountx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgiraldo <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 14:29:48 by mgiraldo #+# #+# */
/* Updated: 2020/02/28 17:10:59 by mgiraldo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Check if ft_checkx can replaced with ft_strstr function
*/
static int ft_checkx(char s, char *c)
{
while (*c)
{
if (s == *c)
return (1);
++c;
}
return (0);
}
int ft_wordcountx(char const *s, char *c)
{
int count;
if (!s || !*c)
return (0);
count = 0;
while (*s)
{
while (ft_checkx(*s, c) && *s)
++s;
if (*s)
++count;
while (!ft_checkx(*s, c) && *s)
++s;
}
return (count);
}