Skip to content

Instantly share code, notes, and snippets.

@aterga
Created September 29, 2012 23:01
Show Gist options
  • Save aterga/3805377 to your computer and use it in GitHub Desktop.
Save aterga/3805377 to your computer and use it in GitHub Desktop.
2-d array fabric
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