alal
This commit is contained in:
parent
e7a7fae345
commit
406545de42
57
du2/program.c
Normal file
57
du2/program.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LINE_SIZE 150
|
||||
#define LIST_SIZE 100
|
||||
|
||||
|
||||
struct pizza{
|
||||
char name[LINE_SIZE];
|
||||
float price
|
||||
};
|
||||
|
||||
int porovnaj(const void *a,const void *b){
|
||||
const struct pizza *p1 = (const struct pizza *)a;
|
||||
const struct pizza *p2 = (const struct pizza *)b;
|
||||
|
||||
if(p1->price < p2-> price) {
|
||||
return -1;
|
||||
}
|
||||
if(p1->price > p2-> price) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int main() {
|
||||
struct pizza list[LIST_SIZE];
|
||||
int = buf;
|
||||
|
||||
while(buf < LIST_SIZE){
|
||||
char meno_buf[LINE_SIZE]
|
||||
char cena_buf[LINE_SIZE]
|
||||
|
||||
if(!fgets(name_buf, LINESIZE, stdin)){
|
||||
break;
|
||||
}
|
||||
meno_buf[strcspn(meno_buf, "\n")] = 0;
|
||||
if(!fgets(cena_buf, LINE_SIZE, stdin)) break;
|
||||
cena_buf[strcspn(cena_buf, "zn")] = 0;
|
||||
if ( strlen(cena_buf) == 0) {
|
||||
break;
|
||||
}
|
||||
float cena;
|
||||
if (sscanf(cena_buf, "%f", &cena) != 1 || cena == 0) {
|
||||
break;
|
||||
}
|
||||
strncpy(list[buf].meno, meno_buf, LINE_SIZE);
|
||||
list[buf].price= price;
|
||||
count++;
|
||||
}
|
||||
qsort(list, buf, sizeof(struct pizza), porovnaj);
|
||||
|
||||
for(int i = 0; i < buf;i++){
|
||||
prinf("%s\n%.6f\n", list[i].meno, list[i].cena
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user