I am quite new to pointers and multi dimensional arrays.
In my code I imgData[0][0] to point to the value of v while imgData[0][1] points to reg.num.
What am I doing wrong?
Thanks
-
#include <stdio.h>
-
#include <string.h>
-
-
struct Region
-
{
-
int num;
-
int minX;
-
int minY;
-
int maxX;
-
int maxY;
-
int pixCount;
-
};
-
-
struct Region my_struct; /* define the structure */
-
void show_name(struct Region *p); /* function prototype */
-
-
int main(void)
-
{
-
struct Region *st_ptr; /* a pointer to a structure */
-
st_ptr = &my_struct; /* point the pointer to my_struct */
-
int *imgData[9][2];
-
int v = 255;
-
my_struct.num = 10;
-
-
imgData[0][0] = &v;
-
imgData[0][1] = &my_struct.num;
-
-
printf("Test 1:%d\n",st_ptr->num);
-
printf("Test 2:%d\n",my_struct.num);
-
-
-
v=2;
-
int i=0;
-
for(i=0;i<9;i++){
-
/** I would expect imgData[0] to be set with the struct and v values. */
-
printf("%d - %d|%d\n", i,imgData[i][0],imgData[i][1] );
-
}
-
-
my_struct.num = 123;
-
my_struct.minX = 63;
-
show_name(st_ptr); /* pass the pointer */
-
-
-
-
return 0;
-
}
-
-
void show_name(struct Region *p)
-
{
-
printf("\n%d ", p->num); /* p points to a structure */
-
printf("%d ", p->minX);
-
printf("%d\n", p->minY);
-
}
-
-
-