Biogenicsoup
Programmer
Hi all
I have tried to generalize my matrix expression in my current program, but have encountered some difficulties with method calls. When i call a method which return void with a pointer to my structure (ex: MatrixInverse(mat, invmat) some of the elements of mat are erased/changed when i return from the method.
The structure is:
the place where i call the method looks like this:
the MatrixInverse method looks like this:
when run the output gives:
mat->type = 2
MatrixInverse called
inmat->type = 2
mat->type = 0
clearly the type variable is changed by returning from the method. This pussles me as i do not change the type variable or the matrix pointer at any time. Does anyone know what I am doing wrong?
Thanks in advance for your help
I have tried to generalize my matrix expression in my current program, but have encountered some difficulties with method calls. When i call a method which return void with a pointer to my structure (ex: MatrixInverse(mat, invmat) some of the elements of mat are erased/changed when i return from the method.
The structure is:
Code:
typedef struct matrix
{ int type;
bool packed;
int cols;
int rows;
FILE* fp;
int** MINT;
char** MCHAR;
double** MDOUBLE;
sparse* MSPARSE;
} matrix;
the place where i call the method looks like this:
Code:
printf("mat->type = %d\n",mat->type);
MatrixInverse(mat, invmat);
printf("mat->type = %d\n",mat->type);
the MatrixInverse method looks like this:
Code:
void MatrixInverse(matrix* inmat, matrix* outmat)
{ printf("MatrixInverse called\n");
fflush((FILE*)0);
int j = 0;
int i;
int n = inmat->rows;
double* col=AllocDoubleArray(n);
inmat=LUDecomp(inmat);
while (j<n)
{ i=0;
while (i<n)
{ col[i]=0.0;
++i;
}
col[j]=1.0;
LULinEq(inmat, col);
i=0;
while (i<n)
{ outmat->MDOUBLE[i][j]=col[i];
++i;
}
++j;
}
DeallocDoubleArray(col, n);
printf("inmat->type = %d\n",inmat->type);
}
when run the output gives:
mat->type = 2
MatrixInverse called
inmat->type = 2
mat->type = 0
clearly the type variable is changed by returning from the method. This pussles me as i do not change the type variable or the matrix pointer at any time. Does anyone know what I am doing wrong?
Thanks in advance for your help