Изменил(а) на 'du5/program.c'

This commit is contained in:
Vladyslav Korzun 2023-03-17 14:35:54 +00:00
parent d50e21770b
commit bf947abf89

View File

@ -43,6 +43,7 @@ int compare_students(const void* a, const void* b) {
int main(){ int main(){
int STOP = 0; int STOP = 0;
int counter = 0;
struct student databaza[SIZE]; struct student databaza[SIZE];
memset(databaza, 0, SIZE*sizeof(struct student)); memset(databaza, 0, SIZE*sizeof(struct student));
int size = 0; int size = 0;
@ -86,14 +87,19 @@ int main(){
else { else {
databaza[id].votes += value; databaza[id].votes += value;
} }
counter++;
} }
qsort(databaza, size, sizeof(struct student), compare_students); qsort(databaza, size, sizeof(struct student), compare_students);
if(counter != 0){
printf("Vysledky:\n"); printf("Vysledky:\n");
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
printf("%d", databaza[i].votes); printf("%d", databaza[i].votes);
printf(" %s\n", databaza[i].name); printf(" %s\n", databaza[i].name);
} }
}
else{
printf("Nepodarilo nacitat nic\n");
}
return 0; return 0;
} }