destroyGrid() frees grid contents and itself.
This commit is contained in:
parent
00ffe88289
commit
ee5c58ad81
10
grid.c
10
grid.c
@ -1,6 +1,7 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <ncurses.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ncurses.h>
|
|
||||||
#include "grid.h"
|
#include "grid.h"
|
||||||
|
|
||||||
// locally used declaration
|
// 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
|
// locally used
|
||||||
// check if cell's next state is alive
|
// check if cell's next state is alive
|
||||||
static bool isAliveNext(Grid* grid, int x, int y)
|
static bool isAliveNext(Grid* grid, int x, int y)
|
||||||
|
3
grid.h
3
grid.h
@ -10,6 +10,7 @@ typedef struct Grid {
|
|||||||
bool* next_state;
|
bool* next_state;
|
||||||
} Grid;
|
} Grid;
|
||||||
|
|
||||||
|
// inits grid and returns pointer to grid. Remember to use Destroy Grid to deallocate
|
||||||
Grid* initGrid(unsigned int width, unsigned int height);
|
Grid* initGrid(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
void randomizeGrid(Grid* grid);
|
void randomizeGrid(Grid* grid);
|
||||||
@ -26,5 +27,7 @@ void setPixel(Grid* grid, int x, int y, bool on);
|
|||||||
|
|
||||||
void drawGrid(Grid* grid);
|
void drawGrid(Grid* grid);
|
||||||
|
|
||||||
|
void destroyGrid(Grid* grid);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user