du2 - 11
This commit is contained in:
parent
0e32584893
commit
8a8a3588cc
@ -31,13 +31,19 @@ int read_pizza(struct pizza *item) {
|
|||||||
}
|
}
|
||||||
line2[strcspn(line2, "\n")] = '\0';
|
line2[strcspn(line2, "\n")] = '\0';
|
||||||
|
|
||||||
float value;
|
float value = 0.0f;
|
||||||
|
if (sscanf(line2, "%f", &value) != 1) {
|
||||||
|
for (int i = 0; line2[i]; i++){
|
||||||
|
if (line2[i] == ',') line2[i] = '.';
|
||||||
|
}
|
||||||
if (sscanf(line2, "%f", &value) != 1){
|
if (sscanf(line2, "%f", &value) != 1){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
strncpy(item->name, line1, LINESIZE - 1);
|
strncpy(item->name, line1, LINESIZE - 1);
|
||||||
item->name[LINESIZE - 1] = '\0';
|
item->name[LINESIZE - 1] = '\0';
|
||||||
|
item->price = value;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,25 +70,24 @@ void sort_pizzas(struct pizza *list, int count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
setlocale(LC_ALL, "C");
|
||||||
|
|
||||||
struct pizza list[MAXITEMS];
|
struct pizza list[MAXITEMS];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
//citanie listka
|
//citanie listka
|
||||||
while (count < MAXITEMS){
|
while (count < MAXITEMS){
|
||||||
struct pizza tmp;
|
struct pizza tmp;
|
||||||
if (!read_pizza(&tmp)){
|
if (!read_pizza(&tmp)) break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
list[count++] = tmp;
|
list[count++] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0) {
|
|
||||||
sort_pizzas(list, count);
|
sort_pizzas(list, count);
|
||||||
|
|
||||||
for (int i = 0; i < count; i++){
|
for (int i = 0; i < count; i++){
|
||||||
printf("%s\n", list[i].name);
|
printf("%s\n", list[i].name);
|
||||||
printf("%.6f\n", list[i].price);
|
printf("%.6f\n", list[i].price);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user