1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem with pointers

Discussion in 'C' started by vinsudhir, Apr 2, 2008.

  1. vinsudhir

    vinsudhir New Member

    Joined:
    Jan 27, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hello,
    I have this small problem.

    Have to 3 dimensional arrays:
    int test1[12][12][12], test2[12][12][12];
    In a for loop, I test a condition, and work on one of them. There are many iterations in the for loop.

    Instead of writing an if-else condition and two seperate codes inside the if-else, I want to have a pointer that points to one of them so that I can use the same code for working on the array.

    To do that, I declare a pointer: int *ptest;
    and I do as assignment: ptest = &test1[0][0][0];

    when I use ptest[j][k], I get a compile time error saying variable is neither an array or pointer.

    Any idea, how I can make this work.

    thanks
     
  2. vinsudhir

    vinsudhir New Member

    Joined:
    Jan 27, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I got it working. I was a single level pointer. I had to use ptest[i*m+j*n+k] to make it work.
     

Share This Page