I've written some code that takes the average of four cells from a 2D array. The conditions are that the columns and rows have to be an even value, if it isn't we ignore the last column/row.
I forgot to mention that this is part of a header file - the 2D array is defined to be a array[x][y] in another file containing the main(). pastebin.com/LUXW5X6b
Given this, I believe the best approach would be to use pointers and malloc to access the heap and make changes. -> How would I go about accomplishing this?
uint8_t *half(const uint8_t array[],
unsigned int cols,
unsigned int rows) {
// your code here
int i, j;
uint8_t new_rows = rows / 2;
uint8_t new_cols = cols / 2;
uint8_t new_array[new_rows][new_cols];
if (new_rows % 2 != 0) {
new_rows = new_rows - 1;
}
if (new_cols % 2 != 0) {
new_cols = new_cols - 1;
}
for (i = 0; i < new_rows; i++) {
for (j = 0; j < new_cols; j++) {
new_array[i][j] = average(array[2*i][2*j],
array[2*i+1][2*j],
array[2*i+1][2*j+1],
array[2*i][2*j+1]);
}
}
return NULL;
}