what wrong with this:

Discussion in 'C++' started by Thorsan, Sep 14, 2004.

  1. Thorsan

    Thorsan Guest

    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
     
    Thorsan, Sep 14, 2004
    #1
    1. Advertising

  2. Bad precedence, see corrections below.

    "Thorsan" <> wrote in message
    news:...
    > 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
     
    John Harrison, Sep 14, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Salisha Khan
    Replies:
    1
    Views:
    11,695
    JohnFol
    Aug 1, 2003
  2. Replies:
    2
    Views:
    402
  3. Pial
    Replies:
    4
    Views:
    57,057
    Phatman
    Aug 27, 2010
  4. Paul Leventis

    Re: Quartus bug or wrong VHDL?

    Paul Leventis, Jun 24, 2003, in forum: VHDL
    Replies:
    0
    Views:
    2,509
    Paul Leventis
    Jun 24, 2003
  5. Matthew
    Replies:
    7
    Views:
    867
    Priscilla Walmsley
    Jan 7, 2005
Loading...

Share This Page