du2 - 3
This commit is contained in:
parent
13e500949d
commit
48bfefad8c
@ -17,18 +17,17 @@ int read_pizza(struct pizza *item) {
|
||||
char line2[LINESIZE];
|
||||
|
||||
//nazov
|
||||
if (!fgets(line1, LINESIZE, stdin)) return 0;
|
||||
if (!fgets(line1, sizeof(line1), stdin)) return 0;
|
||||
line1[strcspn(line1, "\n")] = 0;
|
||||
if (strlen(line1) == 0) return 0;
|
||||
|
||||
//cena
|
||||
if (!fgets(line2, LINESIZE, stdin)) return 0;
|
||||
if (!fgets(line2, sizeof(line2), stdin)) return 0;
|
||||
line2[strcspn(line2, "\n")] = 0;
|
||||
|
||||
float value;
|
||||
if (sscanf(line2, "%f", &value) != 1 || value == 0.0f) {
|
||||
return 0;
|
||||
}
|
||||
float value = 0.0f;
|
||||
if (sscanf(line2, "%f", &value) != 1) return 0;
|
||||
if (value == 0.0f) return 0;
|
||||
|
||||
strcpy(item->name, line1);
|
||||
item->price = value;
|
||||
@ -49,12 +48,16 @@ int compare_pizza(const void *a, const void *b){
|
||||
|
||||
int main() {
|
||||
struct pizza list[MAXITEMS];
|
||||
int count = 0;
|
||||
memset(list, 0, sizeof(list));
|
||||
|
||||
//nacitanie listka
|
||||
int count = 0;
|
||||
while (count < MAXITEMS && read_pizza(&list[count])){
|
||||
count++;
|
||||
}
|
||||
|
||||
//ukoncit ak ziadne polozky
|
||||
if (count == 0) return 0;
|
||||
|
||||
//triedenie
|
||||
qsort(list, count, sizeof(struct pizza), compare_pizza);
|
||||
|
Loading…
Reference in New Issue
Block a user