-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathput_target_view.c
71 lines (63 loc) · 1.39 KB
/
put_target_view.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
//This function will read the input from argv and set the inital matrix states
//This section is for headers and function prototypes (in that order)
#include <stdlib.h>
//Declare struct here
struct solve_state
{
int board[10][9][9];
int views[9][4];
int N;
int x;
int y;
int z;
};
//These functions will strip out whitespaces and return a pointer to the string of only ints
int str_len(char *str) {
int i;
i = 0;
while (str[i] != '\0') {
i++;
}
return (i);
}
int *string_to_int(char *str) {
int i;
int j;
int *intstr;
i = str_len(str);
intstr = (int *)malloc(sizeof(int));
i = 0;
j = 0;
while (i < str_len(str))
{
if (str[i] >= '0' && str[i] <= '9')
{
intstr[j] = str[i] - '0';
j++;
}
i++;
}
return (intstr);
}
struct solve_state put_target_view(struct solve_state current, char *argv)
{
current.x = 0;
current.y = 0;
current.z = 0;
int k;
int *intstr;
intstr = string_to_int(argv);
k = 0;
//Set the values of the target_view matrix using the input
while (current.y < 4)
{
while (current.x < current.N)
{
current.views[current.y][current.x] = intstr[current.x + (current.y * current.N)];
current.x++;
}
current.x = 0;
current.y++;
}
return (current);
}