Created
September 29, 2012 23:01
-
-
Save aterga/3805377 to your computer and use it in GitHub Desktop.
2-d array fabric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIFE **alloc_mass_2d(int ncolumns, int nrows, LIFE init_val) | |
{ | |
LIFE **array = (LIFE **) malloc(nrows * sizeof(LIFE *)); | |
if (array == NULL) | |
{ | |
fprintf(stderr, "out of memory\n"); | |
return NULL; | |
} | |
for (int y = 0; y < nrows; y ++) | |
{ | |
array[y] = (LIFE *) malloc(ncolumns * sizeof(LIFE)); | |
if (array[y] == NULL) | |
{ | |
fprintf(stderr, "out of memory\n"); | |
return NULL; | |
} | |
for (int x = 0; x < ncolumns; x ++) | |
{ | |
array[y][x] = init_val; | |
} | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment