-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.c
75 lines (69 loc) · 1.8 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sinlee <sinlee@student42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/01 12:46:11 by sinlee #+# #+# */
/* Updated: 2023/04/02 17:14:29 by sinlee ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void solve(int arr[4][4]);
void initialize(char *str, int *attr, int arr[4][4])
{
if (attr[1] == 4)
{
attr[1] = 0;
attr[2] += 1;
}
arr[attr[2]][attr[1]] = str[attr[0]] - 48;
attr[1]++;
attr[0]++;
}
int input_to_arr(char *str, int *attr, int arr[4][4])
{
while (str[attr[0]] != '\0')
{
if (str[attr[0]] >= '1' && str[attr[0]] <= '4')
initialize(str, attr, arr);
else if (str[attr[0]] == ' ')
++attr[0];
else
{
write(1, "Error", 5);
return (1);
}
}
if (attr[0] >= 32)
{
write(1, "Error", 5);
return (1);
}
return (0);
}
// i j z
int main(int argc, char **argv)
{
int i;
int arr[4][4];
int attr[3];
if (argc == 2)
{
i = -1;
while (i++ < 3)
attr[i] = 0;
arr[3][3] = -1;
if (input_to_arr(argv[1], attr, arr) == 1)
return (0);
if (arr[3][3] == -1)
write(1, "Error", 5);
if (arr[3][3] == -1)
return (0);
solve(arr);
}
else
write(1, "Error", 5);
return (0);
}