I'm trying to write a compare function for qsort and is having trouble with de-referencing double pointers.
I defined a structure
typedef struct {
float x;
float y;
} point;
and I made an array of pointers to point:
point* ptarr[2]={pt1,pt3} //pt1 and pt3 have type point*
My compare function is defined as follows:
int compare(const void * a, const void * b){
return *(point**)a->x-*(point**)b->x; //This is wrong
}
Since a and b are pointers to the values in the arrays, in my case they are pointers to pointers which point to struct point. Therefore I cast them into double pointer (point**), and then de-referenced it once, and tried to access the values inside struct. Compiler gave me a "request for member 'x' in something not a structure or union" error
I'm really confused about this. Can someone help me with it? thanks
point* ptarr[2]={pt1,pt3}- how did this even compile?point* ptarr[2]={pt1,pt3} //pt1 and pt3 have type pointDoes that actually work ?