From 017b25877ee85aa0eff3a275ee27e2473bb2b311 Mon Sep 17 00:00:00 2001 From: Bohdan Kapliuk Date: Tue, 1 Oct 2024 14:34:03 +0300 Subject: [PATCH] cv2 --- cv2/program.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/cv2/program.c b/cv2/program.c index 6724ae3..8febdd1 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -1 +1,49 @@ -#include \ No newline at end of file +#include +#include +#include +#include + +#define LINESIZE 100 +struct pizza { + char price[LINESIZE]; + char name[LINESIZE]; +}; + +int compare_pizza(const void * a, const void *b){ + return( *(int*)a - *(int*)b); +} + +int main(){ + struct pizza menu[LINESIZE]; + int count = 0; + char vstup[LINESIZE]; + while (count < LINESIZE) { + if (fgets(vstup, LINESIZE, stdin)) { + vstup[strcspn(vstup, "\n")] = '\0'; + if (strlen(vstup) == 0) { + break; + } + strcpy(menu[count].name, vstup); + } else { + break; + } + + if (fgets(vstup, LINESIZE, stdin)) { + vstup[strcspn(vstup, "\n")] = '\0'; + if (strlen(vstup) == 0) { + break; + } + strcpy(menu[count].price, vstup); + } else { + break; + } + count++; + } + qsort (menu->price, count, sizeof(struct pizza), compare_pizza); + for(int i = 0; i < count;i++){ + printf("%s\n", menu[i].name); + float number = strtof(menu[i].price, NULL); + printf("%f\n", number); + } + return 0; +} \ No newline at end of file