-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_countwordspace.c
47 lines (43 loc) · 1.38 KB
/
ft_countwordspace.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_countwordspace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbopp <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 11:08:13 by lbopp #+# #+# */
/* Updated: 2017/02/07 11:14:33 by lbopp ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int verif_quote(char *s, int i, char par)
{
while (s[i])
{
if (s[i] == par)
return (i);
i++;
}
return (-1);
}
int ft_countwordspace(char *s)
{
int i;
int word;
i = 0;
word = 0;
while (s[i])
{
if (!ft_isspace(s[i]))
word++;
while (s[i] && !ft_isspace(s[i]))
{
if ((s[i] == 34 || s[i] == 39) && verif_quote(s, i + 1, s[i]) != -1)
i = verif_quote(s, i + 1, s[i]) + 1;
s[i] ? i++ : 0;
}
while (s[i] && ft_isspace(s[i]))
i++;
}
return (word);
}