From f2a708701068224f2d41c34839fa324ab8907a44 Mon Sep 17 00:00:00 2001 From: Bohdan Yanchyk Date: Thu, 9 Apr 2020 18:54:33 +0000 Subject: [PATCH] =?UTF-8?q?Aktualizovat=20=E2=80=9Edu5/program.c=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- du5/program.c | 117 +++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/du5/program.c b/du5/program.c index 74c43df..fc0f44a 100644 --- a/du5/program.c +++ b/du5/program.c @@ -1,59 +1,60 @@ -#include -#include - -struct person{ - int score; - char name[30]; -} - -void addElement(struct person PersonList*,int score,char *name){ - static int size = 1; - PersonList = realloc(PersonList,size*sizeof(struct person); - PersonList[size-1]->score = score; - PersonList[size-1]->name = name; - size++; -} - - -int comp(const void *p1, const void *p2){ - struct person* person1 = (struct person*)p1; - struct person* person2 = (struct person*)p2; - - return strcmp(person1->name, person2->name); -} - - - -int main(){ - struct person PersonList*=(struct person *)calloc(0,sizeof(struct person)); - int count = 0; - char name[30]; - int score=0; - int c =0; - while(scanf("%d %s",&score,name)!=EOF){ - addElement(&PersonList,score,name); - c++; - } - - qsort(PersonList,c,sizeof(struct person),comp); - int idex = 0; - for(int i =0;i +#include +#include + +struct person{ + int score; + char name[30]; +}; + +void addElement(struct person* PersonList,int score,char *name){ + static int size = 1; + PersonList = realloc(PersonList,size*sizeof(struct person); + PersonList[size-1]->score = score; + PersonList[size-1]->name = name; + size++; +} + + +int comp(const void *p1, const void *p2){ + struct person* person1 = (struct person*)p1; + struct person* person2 = (struct person*)p2; + + return strcmp(person1->name, person2->name); +} + + + +int main(){ + struct person *PersonList=(struct person *)calloc(0,sizeof(struct person)); + int count = 0; + char name[30]; + int score=0; + int c =0; + while(scanf("%d %s",&score,name)!=EOF){ + addElement(&PersonList,score,name); + c++; + } + + qsort(PersonList,c,sizeof(struct person),comp); + int idex = 0; + for(int i =0;i