N
nleahcim
Hi - I am working on writing a number of matrix manipulation functions.
The most basic one was a printing algorithm - and it shows the problem
I'm having. I'm passing it a pointer a mutidimensional array (matrix)
as well as the number of rows and columns. Problem is I don't know what
type the pointer to the multi-dimensional matrix should be. Right now
it's an int * and it works just fine, but when I call the function I
get a warning unless I typecast the array as an int *. What's the
proper way to do this? It's designed to work with any sized two
dimensional arrays. This is the code:
void printmatrix(int * matrix, int rows, int cols)
{
unsigned int rowcounter;
unsigned int colcounter;
for (rowcounter = 0; rowcounter < rows; rowcounter++)
{
for (colcounter = 0; colcounter < cols; colcounter++)
printf("%5i ", *(matrix + rowcounter * cols + colcounter));
printf("\n");
}
}
Thanks!
-Mike
The most basic one was a printing algorithm - and it shows the problem
I'm having. I'm passing it a pointer a mutidimensional array (matrix)
as well as the number of rows and columns. Problem is I don't know what
type the pointer to the multi-dimensional matrix should be. Right now
it's an int * and it works just fine, but when I call the function I
get a warning unless I typecast the array as an int *. What's the
proper way to do this? It's designed to work with any sized two
dimensional arrays. This is the code:
void printmatrix(int * matrix, int rows, int cols)
{
unsigned int rowcounter;
unsigned int colcounter;
for (rowcounter = 0; rowcounter < rows; rowcounter++)
{
for (colcounter = 0; colcounter < cols; colcounter++)
printf("%5i ", *(matrix + rowcounter * cols + colcounter));
printf("\n");
}
}
Thanks!
-Mike