-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_check_pieces.c
More file actions
executable file
·63 lines (57 loc) · 1.73 KB
/
Copy pathft_check_pieces.c
File metadata and controls
executable file
·63 lines (57 loc) · 1.73 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_check_pieces.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akaseris <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/03 21:30:21 by akaseris #+# #+# */
/* Updated: 2017/12/20 10:23:37 by jszabo ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static void ft_check_chars(char s, int *dot, int *hash, int *n)
{
*dot = (s == '.') ? ++*dot : *dot;
*hash = (s == '#') ? ++*hash : *hash;
*n = (s == '\n') ? ++*n : *n;
}
static int ft_pieces(char *s, int dot, int hash, int n)
{
int i;
int pieces;
i = 0;
pieces = 0;
while (s[i])
{
dot = 0;
hash = 0;
n = 0;
while (n < 5 && s[i])
{
if (!(s[i] == '#' || s[i] == '.' || s[i] == '\n'))
return (0);
ft_check_chars(s[i], &dot, &hash, &n);
if (s[i] == '\n' && n != 5 && !((4 * n) == (dot + hash)))
return (0);
i++;
}
pieces++;
if (!(dot == 12 && hash == 4) || (s[i] == '\0' && s[i - 1] == '\n'
&& s[i - 2] == '\n'))
return (0);
}
return (pieces);
}
int ft_check_pieces(char *s)
{
int dot;
int hash;
int n;
int pieces;
dot = 0;
hash = 0;
n = 0;
pieces = ft_pieces(s, dot, hash, n);
return (pieces);
}