diff --git a/cv2/program.c b/cv2/program.c index 72d3ac2..0c07f99 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -5,7 +5,7 @@ #define SIZE 100 -#define NAMESIZE 30 +#define NAMESIZE 50 @@ -22,11 +22,17 @@ int compare_name(const void* c1, const void* c2){ } -int compare_price(const void* c1, const void* c2){ +int compare_float(const void* c1, const void* c2){ struct menu* p1 = (struct menu* ) c1; - struct menu* p2 = (struct menu* ) c2; - return p1->price - p2->price; - + struct menu* p2 = (struct menu* ) c2; + if( p1->price > p2->price ){ + return 1; + }else if( p1->price < p2->price ){ + return -1; + }else{ + return 0; + } + } int main(){ @@ -57,7 +63,7 @@ int main(){ } qsort(food_database,meal_counter,sizeof(struct menu),compare_name); - qsort(food_database,meal_counter,sizeof(struct menu),compare_price); + qsort(food_database,meal_counter,sizeof(struct menu),compare_float); for(int i=0; i