I’m trying to create a 2-d array in my objective c project using regular c, but it is not working correctly.
First of all I declare this in my ViewController.h Interface file…
int selectedItemsInt;
That is the 2-d that I plan to use. Next I create the array in my onload method…
selectedItemsInt [36] [11] = {{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1},{1,1,1,1,1,1,1,1,1,1,1}};
This is a huge 2-d array and I get two errors from it…
Expected expression &AND& Subscripted value is not an array, pointer, or vector
I would put an int in front of the array, but I want to access and edit the array further down in my code…
int index = selectedItemsInt [y][row]; //y and row are ints
and even with that code I get this same error…
Subscripted value is not an array, pointer, or vector
Any help is appreciated!
You need to declare
selectredItemsIntas a two-dimensional array:Then fill it up dynamically in the onload (unless you know the values at declaration time):
If you know the values at declaration time, you can declare and initializa the array in one go:
Note that the first dimension here might be redundant: if you supply the correct number of initialization values, you can do this:
If you supply both the dimension and list the values, but the number of listed values is less than the dimension declared, the end of the array will be uninitialized