Update 'cv2/program.c'

This commit is contained in:
Maryna Kravtsova 2020-10-24 17:06:11 +00:00
parent fe62adf684
commit 594d3cd491

View File

@ -9,6 +9,9 @@ struct pizza{
float prize;
};
//read the name and prize
//push them to stack
int read_pizza(struct pizza* item){
char line1[LINESIZE];
@ -29,12 +32,15 @@ int read_pizza(struct pizza* item){
return 1;
}
}
//compare 2 elements
int compare(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){
if (r == 0){ //if prizes are identical, than check if names are in alphabetical order
r = strcmp(pizza_a->name, pizza_b->name);
}
return r;
@ -48,6 +54,7 @@ int main(){
struct pizza item;
int counter = 0;
//write menu to array
while(stdin, read_pizza(&item)){
strcpy(jedalny_listok[counter].name, item.name);
jedalny_listok[counter].prize = item.prize;