Recently downloaded Z88DK to be able to generate executables for my RC2014 Z80 CPM machine.
It's been a while since I programmed in C.
I am working on a version of 'game of life' as designed by John Conway.
For that I defined two array's of 16 rows and 64 columns.
I declare these as follows:
Code: Select all
#define MAXROW 15
#define MAXCOL 63
....
static char *grid1[MAXROW+1] = {
" * ",
"** * ",
" * ",
" *** ",
.... another 10 lines of spaces ....
" ",
" "
};
Code: Select all
char **lifeGrid = NULL;
char **nextGrid = NULL;
Code: Select all
lifeGrid = grid1;
nextGrid = grid2;
Code: Select all
while (!done) {
displayLifeGrid(); // using pointer 'lifeGrid'
nextGeneration(); // clear the next generation Grid and calculate it anew from the lifeGrid
swapGrids(); // swap the lifeGrid and nextGrid pointer
}
Code: Select all
for (currentRow = 0; currentRow <= MAXROW; currentRow++) {
for (currentCol = 0; currentCol <= MAXCOL; currentCol++) {
// referring to cells like:
if (lifeGrid[currentRow][currentCol] != ' ') // do stuf
}
}
However while running it gives some unexpected results.
Question: Am I handling the definition of these grids properly?
Any help appreciated!
Gerard