diff options
Diffstat (limited to 'serial/src/create_grid.c')
-rw-r--r-- | serial/src/create_grid.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/serial/src/create_grid.c b/serial/src/create_grid.c new file mode 100644 index 0000000..d6a5b94 --- /dev/null +++ b/serial/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); +} |