-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_isvalid.c
109 lines (99 loc) · 2.02 KB
/
ft_isvalid.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
98
99
100
101
102
103
104
105
106
107
108
109
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isvalid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <othmanehachim@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/11 20:54:25 by ohachim #+# #+# */
/* Updated: 2018/11/25 14:58:55 by magoumi ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
static int ft_checktet(char *text)
{
int cn;
int touch;
touch = 0;
cn = 0;
while (text[cn] != '\0')
{
if (text[cn] == '#')
{
if (text[cn + 1] == '#')
touch++;
if (text[cn + 5] == '#')
touch++;
}
cn++;
}
if (touch >= 3)
return (1);
return (0);
}
static int ft_checkp(char *text)
{
int cn;
int p;
p = 0;
cn = 0;
while (text[cn] != '\0')
{
if (text[cn] == '.')
p++;
cn++;
}
if (p != 12)
return (0);
return (1);
}
static int ft_checkhash(char *text)
{
int cn;
int h;
h = 0;
cn = 0;
while (text[cn] != '\0')
{
if (text[cn] == '#')
h++;
cn++;
}
if (h != 4)
return (0);
return (1);
}
static int ft_checkn(char *text)
{
int cn;
int n;
int len;
n = 0;
cn = 0;
len = 0;
while (text[cn] != '\0')
{
if (text[cn] != '\n' && text[cn] != '#' && text[cn] != '.')
return (0);
if (text[cn] == '\n')
{
n++;
if (len != 4)
return (0);
len = 0;
}
else
len++;
cn++;
}
if (n != 4)
return (0);
return (1);
}
int ft_isvalid(char *tets)
{
if (ft_checkn(tets) && ft_checkhash(tets) && ft_checkp(tets)
&& ft_checktet(tets))
return (1);
return (0);
}