4 ms·
You can think of your grid array as a contiguous piece of memory. I would do: bzero(grid, sizeof(int) * COLS); bzero(grid + COLS * (ROWS - 1), sizeof(int)
by licorna 10y ago
You can think of your grid array as a contiguous piece of memory. I would do:
bzero(grid, sizeof(int) * COLS);
bzero(grid + COLS * (ROWS - 1), sizeof(int) * COLS);
for (int i=1; i < ROWS-1; i++) {
*(grid + (i * COLS)) = 0; /* set left col to 0 */
*(grid + (i * COLS) + COLS - 1) = 0; /* set right col to 0 */
}