...

View Full Version : sorting an array of struct by float member



diesavagenation
11-26-2004, 04:59 PM
Ok i'm having touble sorting a member of my struct that is a float w. a qsort.

void sort_by_cost(concert_record concert[]){
int i;
printf("sorting by cost......");
qsort(concert,RECORD_MAX,sizeof(concert),compare_float);
for(i=0;i<RECORD_MAX;i++)
printf("%.2f\n",concert[i].cost);
}

int compare_float(const void *x, const void *y){
return ((concert_record *)x)->cost -
((concert_record *)y)->cost;
}

i have a similar settup for integers and all i did was replace the integer member in these funtions w/ the float member but its not sorting right.... any ideas?

aman
11-26-2004, 09:47 PM
qsort(concert, RECORD_MAX, sizeof(concert_record), compare_f loat);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum