-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2d_array_utils.c
96 lines (80 loc) · 1.72 KB
/
2d_array_utils.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
#include "stdio.h"
#include "stdlib.h"
#include "optional_cell_values.h"
void copy_board_values(int **to, int **from, int size)
{
int i;
int j;
for (i = 0; i < size; ++i)
{
for (j = 0; j < size; ++j)
{
to[i][j] = from[i][j];
}
}
}
void free_2d_array(int **array, int size)
{
int i;
for (i = 0; i < size; ++i)
{
free(array[i]);
}
free(array);
}
void free_possible_values_2d_array(OptionalCellValues **array, int size)
{
int i;
int j;
for (i = 0; i < size; ++i)
{
for (j = 0; j < size; j++)
{
free(array[i][j].propabilities);
}
free(array[i]);
}
free(array);
}
int **create_2d_array(int size)
{
int i;
int **array;
array = (int **)malloc(size * sizeof(int *));
if (array == NULL)
{
printf("Error: create_2d_array has failed\n");
exit(0);
}
for (i = 0; i < size; i++)
{
array[i] = (int *)calloc(size, sizeof(int));
if (array[i] == NULL)
{
printf("Error: create_2d_array has failed\n");
exit(0);
}
}
return array;
}
OptionalCellValues **create_2d_possible_values_array(int size)
{
int i;
OptionalCellValues **array;
array = (OptionalCellValues **)calloc(size, sizeof(OptionalCellValues *));
if (array == NULL)
{
printf("Error: create_2d_array has failed\n");
exit(0);
}
for (i = 0; i < size; i++)
{
array[i] = (OptionalCellValues *)calloc(size, sizeof(OptionalCellValues));
if (array[i] == NULL)
{
printf("Error: create_2d_array has failed\n");
exit(0);
}
}
return array;
}