cv5
This commit is contained in:
parent
377bbc5dee
commit
c8444fa97d
@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#define SIZE 100
|
||||
|
||||
struct student {
|
||||
@ -67,13 +67,16 @@ int main() {
|
||||
char line[SIZE];
|
||||
int votes; // Premenná pre počet hlasov
|
||||
char name[SIZE]; // Pole pre meno
|
||||
bool chyba = false;
|
||||
|
||||
// Načítanie a kontrola formátu vstupu
|
||||
while (1) {
|
||||
|
||||
char* r = fgets(line,SIZE,stdin);
|
||||
if (r == NULL){
|
||||
break;
|
||||
printf("Nepodarilo nacitat nic\n");
|
||||
chyba = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(line[0] == '\n'){
|
||||
@ -105,12 +108,13 @@ int main() {
|
||||
|
||||
// Triedenie študentov pomocou qsort
|
||||
qsort(databaza, size, sizeof(struct student), compare_students);
|
||||
|
||||
|
||||
if (chyba == false){
|
||||
// Výpis výsledkov
|
||||
printf("Výsledky:\n");
|
||||
for (int i = 0; i < size; i++) {
|
||||
printf("%d %s\n", databaza[i].votes, databaza[i].name);
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user