This commit is contained in:
Bohdan Kapliuk 2024-10-06 14:25:30 +03:00
parent 18e9a71ec2
commit 53c6c7d540

View File

@ -20,31 +20,33 @@ int compare_pizza(const void *a, const void *b) {
int main(){
struct pizza menu[LINESIZE];
int count = 0;
char vstup[LINESIZE];
char vstup1[LINESIZE];
char vstup2[LINESIZE];
while (count < LINESIZE) {
if (fgets(vstup, LINESIZE, stdin)) {
vstup[strcspn(vstup, "\n")] = '\0';
vstup1[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';
vstup2[strcspn(vstup, "\n")] = '\0';
if (strlen(vstup) == 0) {
break;
}
float cislo = strtof(vstup, NULL);
menu[count].price = cislo;
float cislo = strtof(vstup2, NULL);
} else {
break;
}
if(cislo != 0){
menu[count].price = cislo;
strcpy(menu[count].name, vstup1);
}
count++;
}
//qsort (menu, count, sizeof(struct pizza), compare_pizza_name);
qsort (menu, count, sizeof(struct pizza), compare_pizza);
for(int i = 0; i < count;i++){
printf("%s\n", menu[i].name);