Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem with pointers (http://www.go4expert.com/forums/problem-with-pointers-t9704/)

vinsudhir 2Apr2008 19:09

Problem with pointers
 
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[i][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

vinsudhir 2Apr2008 22:44

Re: Problem with pointers
 
I got it working. I was a single level pointer. I had to use ptest[i*m+j*n+k] to make it work.


All times are GMT +5.5. The time now is 23:57.