test
This commit is contained in:
parent
3ce1e4ec5d
commit
b83500591d
5
Makefile
5
Makefile
@ -10,3 +10,8 @@ clean:
|
||||
|
||||
anketa: anketa.o main.o
|
||||
gcc anketa.o main.o -o anketa
|
||||
.PHONY: git
|
||||
git:
|
||||
git add .
|
||||
git commit -am "test"
|
||||
git push
|
||||
|
17
anketa.c
17
anketa.c
@ -31,8 +31,10 @@ int add_student(struct student* students, const char* name, int votes){
|
||||
if(index==-1&&pocet<MAXSTUDENTS){
|
||||
strcpy(students[pocet].name,name);
|
||||
students[pocet].votes=votes;
|
||||
return pocet;
|
||||
}else if(pocet<MAXSTUDENTS){
|
||||
students[index].votes+=votes;
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
@ -60,15 +62,12 @@ void print_students(struct student* students){
|
||||
|
||||
void read_students(FILE* file,struct student* students){
|
||||
char meno[100];
|
||||
int body;
|
||||
do{
|
||||
fscanf(file,"%s",&meno[0]);
|
||||
fscanf(file,"%d",&body);
|
||||
if(add_student(students,meno,body)==-1){
|
||||
int body,result;
|
||||
while(fscanf(file,"%s",&meno[0])!=EOF){
|
||||
fscanf(file,"%d",&body);
|
||||
result= add_student(students,meno,body);
|
||||
if(result==-1){
|
||||
break;
|
||||
}
|
||||
}while(meno[0]=EOF);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
42
main.c
42
main.c
@ -1,16 +1,48 @@
|
||||
#include "anketa.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
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));
|
||||
read_students(stdin,students);
|
||||
int sz = count_students(students);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
sort_students(students);
|
||||
print_students(students);
|
||||
|
||||
print_students(students);*/
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user