-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_charachters.c
97 lines (88 loc) · 2.32 KB
/
check_charachters.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_charachters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zszeredi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/15 13:36:54 by zszeredi #+# #+# */
/* Updated: 2020/02/25 14:32:51 by zszeredi ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_check_connections(char *str, char c)
{
int j;
int connections;
connections = 0;
j = 0;
while (str[j] != '\0')
{
if (str[j] == c)
{
if (j > 0 && (str[j + -1] == c && str[j + -1] != '\0'))
connections++;
if (j > 4 && (str[j + -5] == c))
connections++;
}
j++;
}
str[j - 1] = '\0';
if (connections < 3)
return (-1);
return (connections * 2);
}
int ft_charachter(char *str, int j, int n, char c)
{
if (str[j] == c)
n++;
return (n);
}
int ft_check_for_charachter(char *str, int x)
{
int j;
int counter1;
int counter2;
int counter3;
int tmp;
counter1 = 0;
counter2 = 0;
counter3 = 0;
j = 0;
tmp = 0;
while (str[j] != '\0')
{
counter1 = ft_charachter(str, j, counter1, '#');
counter2 = ft_charachter(str, j, counter2, '.');
counter3 = ft_charachter(str, j, counter3, '\n');
j++;
}
str[j] = '\0';
if (counter1 != 4 || counter2 != 12 || counter3 != x)
return (-1);
if ((tmp = ft_check_connections(str, '#')) < 0)
return (-1);
return (1);
}
int ft_check_nl(char *str)
{
if (str[4] != '\n' || str[9] != '\n' || str[14] != '\n' || str[19] != '\n')
return (-1);
return (1);
}
int check_charachters(char *str)
{
int len;
len = ft_strlen(str);
if (len < 20)
return (-1);
if ((ft_check_nl(str) < 0))
return (-1);
if (len == 20)
if ((ft_check_for_charachter(str, 4)) < 0)
return (-1);
if (len == 21)
if ((ft_check_for_charachter(str, 5)) < 0)
return (-1);
return (1);
}