From adc28499849d8b76a9dedead8b82b4155bec8575 Mon Sep 17 00:00:00 2001 From: Maryna Kravtsova Date: Wed, 21 Oct 2020 14:48:39 +0000 Subject: [PATCH] Update 'cv2/program.c' --- cv2/program.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/cv2/program.c b/cv2/program.c index 2a45013..e4ad9a0 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -29,20 +29,14 @@ int read_pizza(struct pizza* item){ return 1; } } -int comparename(const void *a, const void *b){ - - struct pizza* pizza_a = (void*) a; - struct pizza* pizza_b = (void*) b; +int compare(const void *a, const void *b){ - return strcmp(pizza_a->name, pizza_b->name); - -} -int compareprize(const void *a, const void *b){ - struct pizza* pizza_a = (void*) a; struct pizza* pizza_b = (void*) b; - float r = (pizza_a->prize > pizza_b->prize) - (pizza_a->prize < pizza_b->prize); + if (r == 0){ + r = strcmp(pizza_a->name, pizza_b->name); + } return r; } @@ -60,7 +54,7 @@ int main(){ counter++; } - qsort(jedalny_listok, counter, sizeof(struct pizza), compareprize); + qsort(jedalny_listok, counter, sizeof(struct pizza), compare); int i = 0; for(i = 0; i < counter; i++){ @@ -68,7 +62,5 @@ int main(){ printf("%f", jedalny_listok[i].prize); printf("\n"); } - - return 0; }