J
Jim
Hi people. I was hoping someone could help me as this is driving me up
the wall.
I'm trying to write a program that deals with matrix multiplication.
The
Program uses a couple of typedefined structure as follows:
typedef double (*Rowptr)[4]; // Holds rows of 4 doubles
typedef struct {
int Rows;
Rowptr Matrix;
} MatPtr; // Holds number of rows and matricies.
There will always be 4 columns but the number of rows is variable.
Now the problem is, whenever I declare a Matrix and try to assign
individual values as so:
MatPtr NewMatrix;
NewMatric.Matrix[0][0] = 3.2;
NewMatric.Matrix[0][1] = 6.9;
I get run time memory allocation errors.
I can't find a way with malloc (The program must be in C not C++) of
allocating this space in a way the compiler can accept.
I've tried
NewMatrix.Matrix[0] = (Rowptr *) malloc (sizeof(Rowptr));
NewMatrix.Matrix[0] = (double *) malloc (4 * sizeof(double));
NewMatrix.Matrix[0][0] = (double *) malloc (sizeof(double));
....
....
and many more.
Does anyone have any suggestions on a way around this while retraining
the same basic structure.
Any advice would be greatly appreciated as this is driving me slowly
insane
Thanks in advance
Jim
the wall.
I'm trying to write a program that deals with matrix multiplication.
The
Program uses a couple of typedefined structure as follows:
typedef double (*Rowptr)[4]; // Holds rows of 4 doubles
typedef struct {
int Rows;
Rowptr Matrix;
} MatPtr; // Holds number of rows and matricies.
There will always be 4 columns but the number of rows is variable.
Now the problem is, whenever I declare a Matrix and try to assign
individual values as so:
MatPtr NewMatrix;
NewMatric.Matrix[0][0] = 3.2;
NewMatric.Matrix[0][1] = 6.9;
I get run time memory allocation errors.
I can't find a way with malloc (The program must be in C not C++) of
allocating this space in a way the compiler can accept.
I've tried
NewMatrix.Matrix[0] = (Rowptr *) malloc (sizeof(Rowptr));
NewMatrix.Matrix[0] = (double *) malloc (4 * sizeof(double));
NewMatrix.Matrix[0][0] = (double *) malloc (sizeof(double));
....
....
and many more.
Does anyone have any suggestions on a way around this while retraining
the same basic structure.
Any advice would be greatly appreciated as this is driving me slowly
insane
Thanks in advance
Jim