0

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!

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by newbie_in_c
0

Try creating your function like so

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

And calling it like so

myfunction(myarray1, myarray2);

Edited by gerard4143: n/a

0

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;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.