[help]How to get the Pt_ARG_POINTS resource of a polygon?

The PtGetResource() always confuses me. Its parameters are same as PtSetResource, but actually they’re not same.
when try to set points of polygon, i write code like that:
[color=blue]PhPoint_t pnts[4]={{50,50},{100,150},{150,100},{50,50}}
PtSetResource(widget,Pt_ARG_POINTS,pnts,5);
but how can i get all points of that polygon?
[color=red]int i;
PhPoint_t *pnts2[4];
PtGetResource(widget,Pt_ARG_POINTS,&pnts2,0);
for(i=0;i<4;i++)
{
printf(“point i pos is:%d,%d\n”,pnts[i]->x,pnts[i]->y);}
And the result turn out to be:
[color=green]
point 0 pos is:50,50
Memory fault(core dumped)

Can anyone help me to correct the program? Thx in advance!

PhPoint_t pts;
long count;
PtGetResource(widget, Pt_ARG_POINTS, &pts, &count);
for(i=0;i<count;i++) {
/
… */
}

Hope that helps.

Thx for your help.
In fact, that code doesn’t work well. Since pts is a pointer, how can i get each point of polygon?And when i printf count, its value is 13456023,
i change code like this:
[color=red]long *count;
for(i=0;i<*count;i++)
[color=blue]{???//how should I write code here?}
now the value of *count turn out to be 5.
But there’s still a problem: how to get each point of a pointer?

If I change code like this:
[color=red]PhPoint_t *pts[5];
for(i=0;i<5;i++)
{ pts[i]=(PhPoint_t *)malloc(sizeof(PhPoint_t));}

for(i=0;i<*count;i++)
{ printf(“point %d :%d,%d\n”,i,pts[i]->x,pts[i]->y);}

the result is still wrong:
[color=green]point 0:50,50
point 1:0,0
point 2:0,0
point 3:0,0
point 4:0,0

PhPoint_t *ptOld ;
short *num , i ;
PtGetResource( widget , Pt_ARG_POINTS , &ptOld , &num ) ;
for( i = 0; i < *num ; i ++ )
{
printf( “x=%d,y=%d\n” , ( ptOld + i )->x , (ptOld + i )->y ) ;
}

Thx a lot!
Now the code does work well!

sorry, I generally don’t explain basic C pointer stuff in my posts. :slight_smile:

Looks like hzp already posted a good answer and it looks like I goofed up the int param! :slight_smile:

If you look at the docs for Pt_ARG_POINTS, you’ll see that its C type is given as “PhPoint_t*, short”. For array resources, the second type indicates what type to pass for the number of entries.