summaryrefslogtreecommitdiff
path: root/openmp/src/create_grid.c
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2021-12-04 13:34:49 -0700
committerSimponic <loganhunt@simponic.xyz>2021-12-04 13:34:49 -0700
commitaa1d7c6e284cc0818325614391619f3ff13d3e94 (patch)
tree8a59a6b3e5aacb7f682756d3c7751f1d72e1d940 /openmp/src/create_grid.c
downloadgol-aa1d7c6e284cc0818325614391619f3ff13d3e94.tar.gz
gol-aa1d7c6e284cc0818325614391619f3ff13d3e94.zip
Initial commit
Diffstat (limited to 'openmp/src/create_grid.c')
-rw-r--r--openmp/src/create_grid.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/openmp/src/create_grid.c b/openmp/src/create_grid.c
new file mode 100644
index 0000000..d6a5b94
--- /dev/null
+++ b/openmp/src/create_grid.c
@@ -0,0 +1,38 @@
+#include "create_grid.h"
+
+void print_grid(struct GAME* game) {
+ printf("\n===GRID===\n");
+ for (int y = 0; y < game->height; y++) {
+ for (int x = 0; x < game->width; x++) {
+ printf("%i ", game->grid[y][x]);
+ }
+ printf("\n");
+ }
+}
+
+void create_grid(int argc, char** argv) {
+ char* filename;
+ struct GAME game;
+ game.padding = 0;
+ if (argc == 5) {
+ game.width = atoi(argv[2]);
+ game.height = atoi(argv[3]);
+ filename = argv[4];
+ } else {
+ printf("Usage: ./gol create-grid <width> <height> <filename>\n");
+ exit(1);
+ }
+
+ unsigned char** grid = malloc(sizeof(unsigned char*) * game.height);
+ for (int y = 0; y < game.height; y++) {
+ grid[y] = malloc(sizeof(unsigned char*) * game.width);
+ printf("Row %i: ", y);
+ for (int x = 0; x < game.width; x++) {
+ char temp;
+ scanf("%i%c", (unsigned int*)&grid[y][x],&temp);
+ }
+ }
+ game.grid = grid;
+ write_out(filename, &game);
+ print_grid(&game);
+}