How to do int func(int size,int matrix[][size])

Quote:

>>int generate_determinant(int size, int matrix[][size])

>>{ ... }

>>Is this possible?

>mightn't it be just as easy to do

>int generate_determinant( int rows, int columns, int *matrix)

I would tend to solve this as outlined below, given my object-oriented

bent...

typedef struct {

int rows, cols;

int *mat;

Quote:

} matrix_t;

...

matrix_t *create_matrix(int rows, int cols)

{

matrix_t *new_mat = malloc(sizeof(matrix_t));

if (new_mat) {

new_mat->mat = malloc(rows * cols * sizeof(int));

if (new_mat->mat) {

new_mat->rows = rows;

new_mat->cols = cols;

}

else {

free(new_mat);

new_mat = NULL;

}

}

return new_mat;

Quote:

}

void destroy_matrix(matrix_t *matrix)

{

free(matrix->mat);

free(matrix);

Quote:

}

int *matrix_ref(matrix_t *matrix, int row, int col)

{

return matrix->mat + row * matrix->cols + col;

Quote:

}

---------------

Given these definitions, a routine passed a matrix_t automatically knows

its dimensions, and the matrix_ref interface means you don't need to roll

your own address calculations. A typical use might look like:

...

matrix_t *my_matrix;

my_matrix = create_matrix(5, 10);

*matrix_ref(my_matrix, 3, 4) = 12;

and so forth. I have left out some obvious error checking, but I'm sure

you get the idea. I hope this helps!

--

"This sentence is true" : Epiminedes' Paradox -- NOT!

".surivorter erutangis a ma I"