/* * Common code for two versions of game-of-life program: * * Function definitions * * See game-of-life-util.h for comments explaining what these * functions are supposed to do. */ #include #include #include "game-of-life-util.h" bool **build2D(long size) { bool *data = malloc(size * size * sizeof(data[0])); if (data == NULL) { fprintf(stderr, "unable to allocate space for board of size %ld\n", size); return NULL; } bool **array2D = malloc(size * sizeof(array2D[0])); if (array2D == NULL) { fprintf(stderr, "unable to allocate space for board of size %ld\n", size); return NULL; } for (long r = 0; r < size; ++r) { array2D[r] = &data[r*size]; } return array2D; } void free2D(long size, bool **array2D) { bool *data = array2D[0]; free(data); free(array2D); } void update_board(long size, bool **old_board, bool **new_board) { /* FIXME your code goes here */ } void print_board(long size, bool **board) { for (long i = 0; i < size; ++i) { for (long j = 0; j < size; ++j) { if (board[i][j]) printf("1 "); else printf(". "); } putchar('\n'); } }