This commit is contained in:
mr314ot 2025-10-09 19:25:35 +02:00
parent 0e32584893
commit 8a8a3588cc

View File

@ -31,13 +31,19 @@ int read_pizza(struct pizza *item) {
}
line2[strcspn(line2, "\n")] = '\0';
float value;
float value = 0.0f;
if (sscanf(line2, "%f", &value) != 1) {
return 0;
for (int i = 0; line2[i]; i++){
if (line2[i] == ',') line2[i] = '.';
}
if (sscanf(line2, "%f", &value) != 1){
return 0;
}
}
strncpy(item->name, line1, LINESIZE - 1);
item->name[LINESIZE - 1] = '\0';
item->price = value;
return 1;
}
@ -64,24 +70,23 @@ void sort_pizzas(struct pizza *list, int count) {
}
int main() {
setlocale(LC_ALL, "C");
struct pizza list[MAXITEMS];
int count = 0;
//citanie listka
while (count < MAXITEMS){
struct pizza tmp;
if (!read_pizza(&tmp)){
break;
}
if (!read_pizza(&tmp)) break;
list[count++] = tmp;
}
if (count > 0) {
sort_pizzas(list, count);
for (int i = 0; i < count; i++){
printf("%s\n", list[i].name);
printf("%.6f\n", list[i].price);
}
sort_pizzas(list, count);
for (int i = 0; i < count; i++){
printf("%s\n", list[i].name);
printf("%.6f\n", list[i].price);
}
return 0;