2d array call in function reading 1d array

Hi all,

I have the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 int array[4][12] = {
    {1,0,0,0,0,0,0,0,0,0,0,0},
    {1,0,0,1,0,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0,1,0,0,0},
    {1,0,0,0,0,0,1,0,0,0,0,0}};
 int main()
 {
   Calculate();
   Sort();
 }
 void Calculate()
 {
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 12; j++)
        {
            result[i] = Solve(array[i][j]);
        }
    }

  void Sort()
  {
   //Here I sort the values of result and based on this, I also sort the arrays (that is, I exchange the arrays with each other)
  }

  int Solve(int x[])
  {
     //This function returns an int value by using the array x which has 1 dimension but actually this array is 2D as I defined at the beginning (array[4][12]). 
  }


So, how can I use my 2d array in this 1d function? Thanks
Formula:
row * column size + column

So using your array array[4][12]

array[2][6] would be the same as array[2*12+6]
1
2
3
4
5
6
7
void Calculate()
{
    for (int i = 0; i < 4; i++)
    {
        result[i] = Solve(array[i]);
    }
}
Topic archived. No new replies allowed.