This commit is contained in:
Džubara 2024-03-22 00:07:54 +01:00
parent 019daadb45
commit 60852f0d1a

View File

@ -38,7 +38,7 @@ int main() {
int votes; int votes;
while (1) { while (1) {
printf("Enter votes and student name (or 'q' to quit): ");
fgets(line, SIZE, stdin); fgets(line, SIZE, stdin);
// Kontrola ukončenia vstupu // Kontrola ukončenia vstupu
@ -46,8 +46,8 @@ int main() {
break; break;
} }
// Načítanie mena a počtu hlasov zo vstupu // Načítanie počtu hlasov a mena zo vstupu
if (sscanf(line, "%s %d", name, &votes) != 2) { if (sscanf(line, "%d %s", &votes, name) != 2) {
printf("Invalid input. Please try again.\n"); printf("Invalid input. Please try again.\n");
continue; continue;
} }
@ -75,9 +75,8 @@ int main() {
// Výpis triedenej databázy // Výpis triedenej databázy
printf("\nSorted database:\n"); printf("\nSorted database:\n");
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
printf("%d %s\n", database[i].votes, database[i].name); printf("%s: %d votes\n", database[i].name, database[i].votes);
} }
return 0; return 0;
} }