-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_countwords.c
33 lines (29 loc) · 1.15 KB
/
ft_countwords.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_countwords.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abackman <abackman@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/25 16:27:59 by abackman #+# #+# */
/* Updated: 2022/09/27 12:21:14 by abackman ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Returns the number of words in 's' with the delimiter 'c'.
*/
size_t ft_countwords(const char *s, char c)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (s[i] != '\0')
{
if (s[i] != c && (s[i + 1] == c || s[i + 1] == '\0'))
j++;
i++;
}
return (j);
}