what wrong with this:

T

Thorsan

im doing the following:

int _tmain(int argc, _TCHAR* argv[])

{

typedef double matrix4x4[4][4];

matrix4x4 *mat = (matrix4x4*)malloc(sizeof(matrix4x4));

for(int i=0;i<4;i++)

{

for(int j=0;j<4;j++)

{

if(i==j) *mat[j] = 1;

else *mat[j] = 0;
}
//printf("\n");

}


for(int i=0;i<4;i++)

{

for(int j=0;j<4;j++)

{

printf("%f ", *mat[j]);

}

printf("\n");

}

return 0;

}

and it does not work. it works on another computer but not mine.
but if i put in the printf("\n") that i have comented out, it works just fine.
why? I get acess vioalation. The debugger shows something like this:
*mat ..... double[4][4]
*mat .... double[4]
*mat[j] double
....
mat double[4][4]*
mat double[4][4] //this does not seem correct
mat[j] double[4] //this does not seem correct

can anyone help me?

thor andreas
 
J

John Harrison

Bad precedence, see corrections below.

Thorsan said:
im doing the following:

int _tmain(int argc, _TCHAR* argv[])

{

typedef double matrix4x4[4][4];

matrix4x4 *mat = (matrix4x4*)malloc(sizeof(matrix4x4));

for(int i=0;i<4;i++)

{

for(int j=0;j<4;j++)

{

if(i==j) *mat[j] = 1;

else *mat[j] = 0;


if (i == j) (*mat)[j] = 1;
else (*mat)[j] == 0;
}
//printf("\n");

}


for(int i=0;i<4;i++)

{

for(int j=0;j<4;j++)

{

printf("%f ", *mat[j]);


printf("%f ", (*mat)[j]);
}

printf("\n");

}

return 0;

}

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top