From 4552bcf5a4a356415e248dee3b201f0cea7205bb Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Wed, 27 Aug 2025 12:45:33 -0600 Subject: chore: Refactor two_d_arr_init function Return a pointer to a new struct, rather than initialise objects in an existing struct --- max_num_moves_grid.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'max_num_moves_grid.c') diff --git a/max_num_moves_grid.c b/max_num_moves_grid.c index 617135c..119371f 100644 --- a/max_num_moves_grid.c +++ b/max_num_moves_grid.c @@ -35,11 +35,10 @@ int maxMoves(int **grid, int grid_size, int *grid_col_size) { int main() { int g1i[4][4] = {{2, 4, 3, 5}, {5, 4, 9, 3}, {3, 4, 2, 11}, {10, 9, 13, 15}}; int g2i[3][3] = {{3, 2, 4}, {2, 1, 9}, {1, 1, 7}}; - struct two_d_arr g1, g2; - two_d_arr_init(&g1, 4, 4, g1i); - two_d_arr_init(&g2, 3, 3, g2i); - printf("%d\n", maxMoves(g1.arr, g1.row_size, g1.col_size)); // expect: 3 - printf("%d\n", maxMoves(g2.arr, g2.row_size, g2.col_size)); // expect: 0 - two_d_arr_free(&g1); - two_d_arr_free(&g2); + struct two_d_arr *g1 = two_d_arr_init(4, 4, g1i); + struct two_d_arr *g2 = two_d_arr_init(3, 3, g2i); + printf("%d\n", maxMoves(g1->arr, g1->row_size, g1->col_size)); // expect: 3 + printf("%d\n", maxMoves(g2->arr, g2->row_size, g2->col_size)); // expect: 0 + two_d_arr_free(g1); + two_d_arr_free(g2); } -- cgit v1.2.3