PASSINAG A bidimansional array at a function

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ABitLazy

PASSINAG A bidimansional array at a function

Post by ABitLazy »

how do I pass as referance a bidimansional array ata function?

this
int a[1][2];
void f(int **b);
doesnt work ! type mismatch.

-i found this way ...
struct c
{
int *p[2];
} array;

voit initNewType()
{
array.p[0] = &(a[0][0]);
array.p[1] = &(a[0][1]);
}

void f(c *value)
{ //how do i move the array index thru the bidimansioal array?????
*((*value).p[i]+j); //value at a[j][i]....but there 's a mistake someone can help me?
//there's a simpler solution instead that using this mess?

}
main()
{ f(&array);
}

///there's a esyer way to pass by referance a duble array?


if you emailme to [email protected] i'll really apprciate it!
hartyl

RE:PASSINAG A bidimansional array at a function

Post by hartyl »

um... this should work:

void f(int b[3][4])
{ int x=b[1][2];
}

void main()
{ int a[3][4];
  
  f(a);
}

-------------------------
well, you're limited to a fixed size.
if you don't want that, use a one-dimensional array an pass it's size as well.

void f(int b[], int width) //width -> number of elements in a row, the first index
{ int x=b[1*width+2]; //access the same element as above
}

void main()
{ int a[3*4];
  
  f(a,3);
}

hope it helped;
greets, hartyl
Post Reply