Update 'cv2/program.c'
This commit is contained in:
parent
fe62adf684
commit
594d3cd491
@ -9,6 +9,9 @@ struct pizza{
|
|||||||
float prize;
|
float prize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//read the name and prize
|
||||||
|
//push them to stack
|
||||||
|
|
||||||
int read_pizza(struct pizza* item){
|
int read_pizza(struct pizza* item){
|
||||||
|
|
||||||
char line1[LINESIZE];
|
char line1[LINESIZE];
|
||||||
@ -29,12 +32,15 @@ int read_pizza(struct pizza* item){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//compare 2 elements
|
||||||
|
|
||||||
int compare(const void *a, const void *b){
|
int compare(const void *a, const void *b){
|
||||||
|
|
||||||
struct pizza* pizza_a = (void*) a;
|
struct pizza* pizza_a = (void*) a;
|
||||||
struct pizza* pizza_b = (void*) b;
|
struct pizza* pizza_b = (void*) b;
|
||||||
float r = (pizza_a->prize > pizza_b->prize) - (pizza_a->prize < pizza_b->prize);
|
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);
|
r = strcmp(pizza_a->name, pizza_b->name);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@ -48,6 +54,7 @@ int main(){
|
|||||||
struct pizza item;
|
struct pizza item;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
||||||
|
//write menu to array
|
||||||
while(stdin, read_pizza(&item)){
|
while(stdin, read_pizza(&item)){
|
||||||
strcpy(jedalny_listok[counter].name, item.name);
|
strcpy(jedalny_listok[counter].name, item.name);
|
||||||
jedalny_listok[counter].prize = item.prize;
|
jedalny_listok[counter].prize = item.prize;
|
||||||
|
Loading…
Reference in New Issue
Block a user