This commit is contained in:
Michaela Šaková 2019-03-25 15:37:46 +01:00
parent b83500591d
commit c9a74987d0
6 changed files with 15 additions and 4 deletions

BIN
anketa

Binary file not shown.

View File

@ -45,11 +45,16 @@ int add_student(struct student* students, const char* name, int votes){
int compare(const void* s1,const void* s2){ int compare(const void* s1,const void* s2){
struct student* stud1=(struct student*)s1; struct student* stud1=(struct student*)s1;
struct student* stud2=(struct student*)s2; struct student* stud2=(struct student*)s2;
return stud1->votes==stud2->votes?0:stud1->votes<stud2->votes?1:-1; if(stud1->votes==stud2->votes){
return 0;
}else if(stud1->votes<stud2->votes){
return 1;
}
return -1;
} }
void sort_students(struct student* students){ void sort_students(struct student* students){
qsort(students, count_students(students), sizeof(struct student), compare); qsort(students,count_students(students),sizeof(struct student),compare);
} }
void print_students(struct student* students){ void print_students(struct student* students){

BIN
anketa.o

Binary file not shown.

3
main.c
View File

@ -29,7 +29,8 @@ int main(int argc,char** argv){
break; break;
case 'p': print_students(students); case 'p': print_students(students);
break; break;
case 'o': sort_students(students); case 'o': sort_students(students);
print_students(students);
break; break;
case 'c': count_votes(students); case 'c': count_votes(students);
break; break;

BIN
main.o

Binary file not shown.

View File

@ -2,4 +2,9 @@ Anka
10 10
Marcel Marcel
30 30
Anka
5
Jozko
590
Anka
1000