This commit is contained in:
mr314ot 2025-10-09 08:58:10 +02:00
parent 48bfefad8c
commit 421f2ea58b

View File

@ -2,7 +2,7 @@
#include <stdlib.h>
#include <string.h>
#define LINESIZE 100
#define LINESIZE 200
#define MAXITEMS 100
// struktura pre polozku jed. listka
@ -17,17 +17,24 @@ int read_pizza(struct pizza *item) {
char line2[LINESIZE];
//nazov
if (!fgets(line1, sizeof(line1), stdin)) return 0;
line1[strcspn(line1, "\n")] = 0;
if (strlen(line1) == 0) return 0;
if (fgets(line1, sizeof(line1), stdin) == NULL) {
return 0;
}
line1[strcspn(line1, "\n")] = '\0';
if (line1[0] == '\0') {
return 0;
}
//cena
if (!fgets(line2, sizeof(line2), stdin)) return 0;
line2[strcspn(line2, "\n")] = 0;
if (fgets(line2, sizeof(line2), stdin) == NULL) {
return 0;
}
line2[strcspn(line2, "\n")] = '\0';
float value = 0.0f;
if (sscanf(line2, "%f", &value) != 1) return 0;
if (value == 0.0f) return 0;
float value;
if (sscanf(line2, "%f", &value) != 1) {
return 0;
}
strcpy(item->name, line1);
item->price = value;
@ -48,16 +55,17 @@ int compare_pizza(const void *a, const void *b){
int main() {
struct pizza list[MAXITEMS];
memset(list, 0, sizeof(list));
int count = 0;
//nacitanie listka
int count = 0;
while (count < MAXITEMS && read_pizza(&list[count])){
count++;
}
//ukoncit ak ziadne polozky
if (count == 0) return 0;
if (count == 0) {
return 0;
}
//triedenie
qsort(list, count, sizeof(struct pizza), compare_pizza);