Hello all,
I've searched a lot and found a bunch of answers and edited my comparison many many times, but just cannot get a sorted output.
Here is my struct
typedef struct sortedDistance {
int storeID;
int zipCode;
double latitude;
double longitude;
double distance;
char address[50];
char city[50];
char state[20];
} sortedDistance;
I want to sort by "double distance"
Here is my qsort() function call
qsort( sortedArray, sizeSortedDistanceArray, sizeof( sortedDistance ), compare );
And finally, here is my compare function
int compare( const void* a, const void* b ) {
const sortedDistance *ia = (const sortedDistance *) a;
const sortedDistance *ib = (const sortedDistance *) b;
if( ia->distance < ib->distance ) return -1;
if( ia->distance > ib->distance ) return 1;
else return 0;
}
I've tried many different things, and I just cannot get it to sort by distance element of the struct array. Any assistance would be helpful!