-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse2.c
74 lines (67 loc) · 1.68 KB
/
parse2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: toramo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/18 10:06:01 by toramo #+# #+# */
/* Updated: 2023/12/18 10:06:02 by toramo ### ########.fr */
/* */
/* ************************************************************************** */
#include "include/fdf.h"
int count_wordsperline(char *str)
{
int i;
int count;
count = 0;
i = 0;
if (ft_isdigit(str[i]) || str[i] == '-')
{
count++;
i++;
}
else
while (str[i] == ' ')
i++;
while (str[i] != '\n' && str[i])
{
if (str[i - 1] == ' ' && str[i] != ' ' && str[i] != '\n')
count++;
i++;
}
return (count);
}
int wordsperline_max(char *map)
{
int i;
int maxwpl;
i = 0;
maxwpl = 0;
while (map[i])
{
if (count_wordsperline(&map[i]) > maxwpl)
maxwpl = count_wordsperline(&map[i]);
while (map[i] != '\n' && map[i] != 0)
i++;
if (map[i] == '\n')
i++;
}
return (maxwpl);
}
int count_lines(char *map)
{
int i;
int count;
i = 0;
count = 0;
while (map[i])
{
if (map[i] == '\n')
count++;
i++;
}
if (map[i - 1] != '\n' && i > 0)
count++;
return (count);
}