-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_countwordchar.c
47 lines (43 loc) · 1.35 KB
/
ft_countwordchar.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_countwordchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbopp <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/03 09:40:30 by lbopp #+# #+# */
/* Updated: 2017/02/03 16:50:58 by lbopp ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int verif_quote(char *s, int i, char par)
{
while (s[i])
{
if (s[i] == par)
return (i);
i++;
}
return (-1);
}
int ft_countwordchar(char *s, char c)
{
int i;
int word;
i = 0;
word = 0;
while (s[i])
{
if (s[i] != c)
word++;
while (s[i] && s[i] != c)
{
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] && s[i] == c)
i++;
}
return (word);
}