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:
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?
2 Answers 2
If you would try to pass a 1-D array to function like this then its perfect what you did, but in case you are trying to pass 2-D array then u need to pass the array with its valid syntax, which is not just like the 1-D
i.e. return_type function_name(dataType arrayName[100],int size)
in case you can also leave the subscripts ‘[]’ as blank for 1-D array ONLY,
but for 2-D array it would be
return_type function_name(dataType arrayName[100][100],int rowSize,int colSize)
however you can also leave the subscripts ‘[]’ to be blank here also but only the 1st [] and 2nd must have to contain some value in it. actually it doesn’t matter what value you passed in 2nd subscripts, but some value should has to be there, just pass a value to which your 2-D array would not exceed.
And the syntax will keep going like this for further dimensions of array. Hope this will work for you.
#include
#include
#include
using namespace std;
int minim(int mas,int siz)
<
int min; //минимальный элемент массива
min = mas[0];
for (int i = 0; i >size;
int* arr = new int[size];
cout >sluch1;
cout >sluch2;
for(int i=0;i Голосование за лучший ответ
Дальше какая-то чушь. Arr и arr — зачем две переменных?

Compiler errors:
(In main)
Line 9:cannot convert char (*)[3] to char* for argument 1 to void showboard(char*, int, int)
(in showBoard)
Lines 16, 17, 21, 22, 26, 27:invalid types char[int] for array subscript
I don’t understand these errors. I am trying to make a tic tac toe game, I have to initialize the board with ‘*’s. Right now I am merely trying to display the board with the ‘*’s. I have searched the forums and although there are a lot of tic tac toe threads none apply to me. Any help would be greatly appreciated, thanks!