Archived

This topic is now archived and is closed to further replies.

*(*(ptr+row)+column) : Invalid indirection ?

This topic is 5752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have a two dimensional array: int Array[][4]; with some values and a pointer to it: int *ptr = Array[0][0]; When I try to access the values in the array using *(*(ptr+row)+column), I get an invalid indirection error. row and column are loop variables and are declared. What is the problem and how do I correct it? I am using Borland C++ 5.5 compiler.

Share this post


Link to post
Share on other sites
1. You should be getting the address of Array[0][0]
2. *(*(ptr)) you're trying to dereferencing a object
3. *(*(ptr+row)+column) You're array math is wrong


      
int row=3,column=2;
int Array[][4]=
{
01,02,03,04,
11,12,13,14,
21,22,23,24,
31,32,33,34,
};
int *ptr = &Array[0][0];
int a = *(ptr+(row*4+column));
printf("%d",a);


So that prints 33 which is correct.

Edit: And Oluseyi types faster than me


[edited by - burp on March 20, 2002 2:34:15 AM]

Share this post


Link to post
Share on other sites
I have tried using Oluseyi''s method, but I get access violations
Thanks burp for the second method, but I already know this one since all the values are stored in continuos (damn! what is the spelling?) locations. I appreciate the help.

I actually saw what I was trying, in this link http://www.gamedev.net/reference/articles/article1697.asp here but am unable to get the stuff working.

BTW anyone know how of any utility to combine bitmaps and get the texture coordinates or do I have to combine it the hard way by writing code to join the bitmaps?

Amresh
ramresh@dsqsoft.com

Share this post


Link to post
Share on other sites
If you mean chapter 7? Then this should help out a bit more.


    
int row=3,col=2;
int Array[][4]=
{
01,02,03,04,
11,12,13,14,
21,22,23,24,
31,32,33,34,
};

printf("%d\n",*(*(Array + row) + col));

int *ptr1 = &Array[0][0];
printf("%d\n",*(ptr1+(row*4+col)));

int (*ptr2)[4] = Array;
printf("%d\n",*(*(ptr2 + row) + col));


[edited by - burp on March 20, 2002 6:03:44 AM]

Share this post


Link to post
Share on other sites