Hello. Currently trying to have a 2D array that serves as memory to be changed on a switch case function. When inside the function I write the code to change the determined element of the array by the case, I get 2 errors: The first one “Array initializer must be an initializer list” on the first case and then for every other case I get “Redefinition of ‘memory’ with a different type: ‘int [y]’ vs ‘int [0][0]’”. I’ve tried everything from including the “&” on the variable parsed in the functioned(which is removed on this snippet) or “*” symbol but later learned that the parsing itself is already a pointer so it’s redundant, etc, and every time a new error pops up.
I’ve also tried this code on programix online compiler and it works. I’m truly lost. Bellow I’ll show the relevant snippet of the code. Any help to an MBED begginer is greatly appreciated
int memory [2][8] = {{0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0}};
void exit_on(int exit){
switch (exit){
case 1:
memory[0][0]=1;
break;
case 2:
memory [0][1]={1};
break;
case 3:
memory[0][2]=1;
break;
case 4:
memory[0][3]=1;
break;
case 5:
memory[0][4]=1;
break;
case 6:
memory[0][5]=1;
break;
case 7:
memory[0][6]=1;
break;
case 8:
memory[0][7]=1;
break;
case 9:
memory[1][0]=1;
break;
case 10:
memory[1][1]=1;
break;
case 11:
memory[1][2]=1;
break;
case 12:
memory[1][3]=1;
break;
case 13:
memory[1][4]=1;
break;
case 14:
memory[1][5]=1;
break;
case 15:
memory[1][6]=1;
break;
case 16:
memory[1][7]=1;
break;
default:
printf("Error\n");
break;
}
}