Sunday, August 2, 2009

How can we pass a multidimensional array to a function in C?

You pass a pointer to it.


void doStuff(char **pJunk) {


...


}





int main(int argc, char *argv[]) {


char junk[3][4];





... fill it in





doStuff(junk);





}

How can we pass a multidimensional array to a function in C?
Toadaly's solution doesn't tell how the function would know the array's dimensions...
Reply:#define COLUMN 3





void Dump(int buffer[][COLUMN])


{


for(int row=0; row %26lt; 5; row++)


for(col = 0; col %26lt; COLUMN; col++)


printf ("row: %d\tcol: %d\t%d\n", x, y, buffer[row][col]);


}





int main()


{


int g[5][COLUMN];





/* fill g up */





Dump(g);





return(1);


}

floral centerpieces

No comments:

Post a Comment