From 1332dbc534681d9ccc8a01af236245c2eac57c86 Mon Sep 17 00:00:00 2001 From: Andrii Hermaniuk Date: Thu, 7 Apr 2022 16:45:48 +0200 Subject: [PATCH] ds --- du5/program.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/du5/program.c b/du5/program.c index e1e3610..73e3669 100644 --- a/du5/program.c +++ b/du5/program.c @@ -38,13 +38,15 @@ int main(){ int id = find_student(databaza,size,name); if (id< 0){ - // Skopirujte zaznam na posledne miesto v poli + memcpy(databaza[size].name,name,strlen(name)+1); databaza[size].votes=value; - // Zvacsite pocet zaznamov + size+=1; - if(size>1) + if(size>1){ + //printf("=====================================\n"); qsort(databaza, size, sizeof(struct student), compare); + } } else { databaza[id].votes+=value; @@ -54,6 +56,7 @@ int main(){ for(int idx=0;databaza[idx].name[0]!='\0';idx++) printf("%d %s", databaza[idx].votes, databaza[idx].name); + //printf("\n"); return EXIT_SUCCESS; } @@ -65,12 +68,17 @@ int find_student(struct student* students,int size, const char* name){ int compare(const void* p1, const void* p2){ struct student* s1 = (struct student*)p1; struct student* s2 = (struct student*)p2; - + + //printf("============\n"); int res=(s2->votes)-(s1->votes); - for(int idx=0; res==0||(s1->name[idx])!='\0';idx++){ - res=(int)(s2->name[idx])-(int)(s1->name[idx]); + + for(int idx=0;res==0&&idxname[idx])-(int)(s2->name[idx]); + //printf("%d, %c, %c\n",res,s2->name[idx],s1->name[idx]); } - - return (s2->votes)-(s1->votes); + + return res; } + +