I'm working on a program that does some matrix math. Fortunately the code logic is not what is giving me the errors.
I am using the following code to output a matrix that is stored in a 2-d array:
void ouputMatrix(char arr[], int matrixRows, int matrixColumns) {
for (int a=0; a<matrixRows; a++) {
for (int i=0; i<matrixColumns; i++) {
cout << arr[a][i] << " ";
}
cout << endl;
}
cout << endl;
}
However when I try to compile this code, I am told:
"In function 'void outputMatrix(char*, int, int)': [Error] Invalid types 'char[int]' for array subscript.
The error type suggests to me that I am missing something obvious with regards to c++ array syntax or something like that but I cannot figure it out. What am I doing wrong?
arr[a]is achar. You cannot do[i]on achar. I guess you meant to pass a 2-D array instead ofchar arr[]