Hello all,

I've a small question. I wanna use a function void myfunction(int **array1, int **array2) where array1 and array2 shoud be [4][4]. I've added 2 arrays
int myarray1[4][4], myarray2[4][4];

and called my function like this: myfunction(&myarray1[0], &myarray2[0]);

I've got the following warning message :
warning: passing argument 1 of 'myfunction' from incompatible pointer type
warning: passing argument 2 of 'myfunction' from incompatible pointer type

Could you help me out please?

Thank you!

Try creating your function like so

void myfunction(int array1[][4], int array2[][4])

And calling it like so

myfunction(myarray1, myarray2);

I can't change myfunction. I can only use it.

Thank you.

Try looking at the code below.

#include <stdio.h>
#include <stdlib.h>

void myfunction(int **array1, int **array2)
{
  int i = 0, j = 0;
  
  for (i = 0; i < 4; ++i)
  {
	for (j = 0; j < 4; ++j)
	{
	  fprintf(stdout, "ans->%d\n", array1[i][j]);
	  fprintf(stdout, "ans->%d\n", array2[i][j]);
	}
  }
  
}

int main(int argc, char**argv)
{
  int i = 0, j = 0;
  int **myarray1;
  int **myarray2;
  
  myarray1 = (int**)malloc(4 * sizeof(int*));
  myarray2 = (int**)malloc(4 * sizeof(int*));
  
  for (i = 0; i < 4; +++i)
	myarray1[i] = (int*)malloc(4 * sizeof(int));
  
  for (i = 0; i < 4; +++i)
	myarray2[i] = (int*)malloc(4 * sizeof(int));
  
  for (i = 0; i < 4; ++i)
  {
	for (j = 0; j < 4; ++j)
	{
	  myarray1[i][j] = i + j;
	  myarray2[i][j] = i + j;
	}
  }
 
  myfunction(myarray1, myarray2);
  /*free memory here*/
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.