From 406545de42d5f923397b6d8a223f78d3f682620e Mon Sep 17 00:00:00 2001 From: Matej Hajduk Date: Wed, 1 Oct 2025 10:14:45 +0200 Subject: [PATCH] alal --- du2/program.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 du2/program.c diff --git a/du2/program.c b/du2/program.c new file mode 100644 index 0000000..811d462 --- /dev/null +++ b/du2/program.c @@ -0,0 +1,57 @@ +#include +#include +#include + +#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; +}