test
This commit is contained in:
parent
1b87440824
commit
3ce1e4ec5d
23
anketa.c
23
anketa.c
@ -27,27 +27,14 @@ int search(struct student* students,const char* name){
|
||||
}
|
||||
|
||||
int add_student(struct student* students, const char* name, int votes){
|
||||
int index=-1, x=0;
|
||||
for(int i=0; i<MAXSTUDENTS; i++){
|
||||
if(strcmp(students[i].name,name)==0){
|
||||
index=i;
|
||||
break;
|
||||
}
|
||||
if(students[i].name!=NULL){
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
if(index!=-1){
|
||||
int index=search(students,name),pocet=count_students(students);
|
||||
if(index==-1&&pocet<MAXSTUDENTS){
|
||||
strcpy(students[pocet].name,name);
|
||||
students[pocet].votes=votes;
|
||||
}else if(pocet<MAXSTUDENTS){
|
||||
students[index].votes+=votes;
|
||||
return index;
|
||||
}
|
||||
|
||||
if(x<(MAXSTUDENTS-1)){
|
||||
strcpy(students[x].name,name);
|
||||
students[x].votes=votes;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user