Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what wrong with this:

Reply
Thread Tools

what wrong with this:

 
 
Thorsan
Guest
Posts: n/a
 
      09-14-2004
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[i][j] = 1;

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

}


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

{

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

{

printf("%f ", *mat[i][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[i] .... double[4]
*mat[i][j] double
....
mat double[4][4]*
mat[i] double[4][4] //this does not seem correct
mat[i][j] double[4] //this does not seem correct

can anyone help me?

thor andreas
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      09-14-2004
Bad precedence, see corrections below.

"Thorsan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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[i][j] = 1;
>
> else *mat[i][j] = 0;


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

> }
> //printf("\n");
>
> }
>
>
> for(int i=0;i<4;i++)
>
> {
>
> for(int j=0;j<4;j++)
>
> {
>
> printf("%f ", *mat[i][j]);


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

>
> }
>
> printf("\n");
>
> }
>
> return 0;
>
> }
>


john


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments