-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.c
86 lines (79 loc) · 2.16 KB
/
func.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* func.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* Tg: @elshirak +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/09 20:03:36 by ELSHIRAK #+# #+# */
/* Updated: 2022/10/09 23:28:36 by ELSHIRAK ### ########.fr */
/* */
/* ************************************************************************** */
#include "lib.h"
int ft_check_cond(char *str) // the same thing is done by f_parse, however if it works - do not touch
{
int i;
i = 0;
while (str[i] != '\0')
{
if (!(str[i] >= 49 && str[i] <= 52) && (str[i + 1] == 32))
return (0);
else if (str[i] == 32 && str[i + 1] == 32)
return (0);
else if ((str[i] >= 49 && str[i] <= 52)
&& (str[i + 1] >= 49 && str[i + 1] <= 52))
return (0);
i++;
}
return (i);
}
int ft_parse(char **board, char *values) // parsing values, cheking if they are OK with subject
// we can input only [1, 4] numeric
{
int i;
char c;
i = 0;
while (i < 4)
{
c = values[i * 2] - 48;
if (c <= 0 || c > 4)
return (0);
board[0][i + 1] = c;
c = values[i * 2 + 8] - 48;
if (c <= 0 || c > 4)
return (0);
board[5][i + 1] = c;
c = values[i * 2 + 16] - 48;
if (c <= 0 || c > 4)
return (0);
board[i + 1][0] = c;
c = values[i * 2 + 24] - 48;
if (c <= 0 || c > 4)
return (0);
board[i + 1][5] = c;
i++;
}
return (1);
}
void print_board(char **board) // print result matrix
{
int i;
int j;
char c;
i = 1;
while (i < 5)
{
j = 1;
while (j < 5)
{
c = board[i][j] + 48;
write(1, &c, 1);
if (j != 4)
write(1, " ", 1);
else
write(1, "\n", 1);
j ++;
}
i ++;
}
}