I'm trying to return a 2D array from a function after passing a 2D array. This is how far I've gotten, but I'm still getting a plethora of compilation errors. I've tried searching what the error means however I'm still incredibly confused. I'm attempting to rotate an array of values by 90 degrees. There is my code:
// Rotate Array 90 degrees
char * Rotate90Array(char *array, int rowCount, int columnCount) {
// These have to be swapped because the image is being rotated
char *returnArray[columnCount][rowCount];
int u = rowCount - 1;
int v = columnCount - 1;
int i = 0;
int j = 0;
for (i = 0; i < rowCount; i++) {
for (j = 0; j < columnCount; j++) {
returnArray[i][j] = array[u-j][i];
j++;
}
i++;
}
return returnArray;
}
Here are my errors relevant to this function:
P-MFunctionHolder.c: In function 'Rotate90Array':
P-MFunctionHolder.c:211:34: error: subscripted value is neither array nor pointer nor vector
P-MFunctionHolder.c:216:2: warning: return from incompatible pointer type [enabled by default]
P-MFunctionHolder.c:216:2: warning: function returns address of local variable [enabled by default]
I also have another function that calls upon the previous one twice, to rotate the array 180 degrees, and this is giving me similar errors. Here is the code:
// Rotate Array 180 degrees
char * Rotate180Array(char *array, int rowCount, int columnCount) {
char returnArray1[rowCount][columnCount] = Rotate90Array(array, rowCount, columnCount);
char returnArray2[rowCount][columnCount] = Rotate90Array(returnArray1, rowCount, columnCount);
return returnArray2;
}
Here are the errors relevant to this function:
P-MFunctionHolder.c: In function 'Rotate180Array':
P-MFunctionHolder.c:222:2: error: variable-sized object may not be initialized
P-MFunctionHolder.c:223:2: error: variable-sized object may not be initialized
P-MFunctionHolder.c:223:2: warning: passing argument 1 of 'Rotate90Array' from incompatible pointer type [enabled by default]
P-MFunctionHolder.c:199:8: note: expected 'char *' but argument is of type 'char (*)[(sizetype)(columnCount)]'
P-MFunctionHolder.c:224:2: warning: return from incompatible pointer type [enabled by default]
P-MFunctionHolder.c:224:2: warning: function returns address of local variable [enabled by default]