diff --git a/grid.c b/grid.c index a7cc0f9..ad8c8fc 100644 --- a/grid.c +++ b/grid.c @@ -1,6 +1,7 @@ +#include +#include #include #include -#include #include "grid.h" // locally used declaration @@ -78,6 +79,13 @@ void drawGrid(Grid* grid) } } +void destroyGrid(Grid* grid) +{ + free(grid->state); + free(grid->next_state); + free(grid); + printf("Grid destroyed\n"); +} // locally used // check if cell's next state is alive static bool isAliveNext(Grid* grid, int x, int y) diff --git a/grid.h b/grid.h index fa18e09..5990206 100644 --- a/grid.h +++ b/grid.h @@ -10,6 +10,7 @@ typedef struct Grid { bool* next_state; } Grid; +// inits grid and returns pointer to grid. Remember to use Destroy Grid to deallocate Grid* initGrid(unsigned int width, unsigned int height); void randomizeGrid(Grid* grid); @@ -26,5 +27,7 @@ void setPixel(Grid* grid, int x, int y, bool on); void drawGrid(Grid* grid); +void destroyGrid(Grid* grid); + #endif