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

Started by
3 comments, last by amreshr 22 years, 1 month ago
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.
dArkteMplaR of Delphi
Advertisement
You''re dereferencing twice, but only declared one layer of indirection. Try int **ptr = &Array[0]; That way, *ptr is Array[0] and *(ptr + n) is Array[n][0].

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
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]
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
dArkteMplaR of Delphi
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]

This topic is closed to new replies.

Advertisement