50 lines
1.4 KiB
C
50 lines
1.4 KiB
C
#include "anketa.h"
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
void count_votes(struct student* students){
|
|
int sum=0;
|
|
for(int i=0;i<count_students(students);i++){
|
|
sum+=students[i].votes;
|
|
}
|
|
printf("%d\n",sum);
|
|
}
|
|
|
|
int main(int argc,char** argv){
|
|
int index;
|
|
struct student students[MAXSTUDENTS];
|
|
memset(students,0,sizeof(struct student)*(MAXSTUDENTS));
|
|
if(argc>1){
|
|
FILE* fr=fopen(argv[1],"r");
|
|
read_students(fr,students);
|
|
switch(argv[2][1]){
|
|
case 'h': printf("-h vypise navod na ovladanie.\n-s vyhlada zadane meno.\n-p vypise vyslednu databazu mien.\n-o zotriedi vyslednu databazu podla pocetnosti.\n-c vypise pocet vsetkych odovzdanych hlasov.\n-i vypise pocet studentov, ktori dostali aspon jeden hlas.\n");
|
|
break;
|
|
case 's': index=search(students,argv[3]);
|
|
if(index!=-1){
|
|
printf("%s\n %d\n", students[index].name, students[index].votes);
|
|
}else{
|
|
printf("Hladany student sa nenasiel.\n");
|
|
}
|
|
break;
|
|
case 'p': print_students(students);
|
|
break;
|
|
case 'o': sort_students(students);
|
|
print_students(students);
|
|
break;
|
|
case 'c': count_votes(students);
|
|
break;
|
|
case 'i': printf("%d\n", count_students(students));
|
|
break;
|
|
}
|
|
}
|
|
/* int sz = count_students(students);
|
|
if (sz <= 0){
|
|
// Nenacitalo sa nic
|
|
return 0;
|
|
}
|
|
|
|
print_students(students);*/
|
|
return 0;
|
|
}
|