pvjc19cv5/main.c

50 lines
1.4 KiB
C
Raw Normal View History

2019-03-23 18:14:52 +00:00
#include "anketa.h"
#include <string.h>
2019-03-25 14:17:05 +00:00
#include <stdio.h>
2019-03-23 18:14:52 +00:00
2019-03-25 14:17:05 +00:00
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;
2019-03-23 18:14:52 +00:00
struct student students[MAXSTUDENTS];
memset(students,0,sizeof(struct student)*(MAXSTUDENTS));
2019-03-25 14:17:05 +00:00
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;
2019-03-25 14:37:46 +00:00
case 'o': sort_students(students);
print_students(students);
2019-03-25 14:17:05 +00:00
break;
case 'c': count_votes(students);
break;
case 'i': printf("%d\n", count_students(students));
break;
}
}
/* int sz = count_students(students);
2019-03-23 18:14:52 +00:00
if (sz <= 0){
// Nenacitalo sa nic
return 0;
}
2019-03-25 14:17:05 +00:00
print_students(students);*/
2019-03-23 18:14:52 +00:00
return 0;
}