Aktualizovat „du5/program.c“

This commit is contained in:
Bohdan Yanchyk 2020-04-09 19:20:10 +00:00
parent 42822617e6
commit 46483a5b2e

View File

@ -8,7 +8,7 @@ struct person{
char name[30]; char name[30];
}; };
void addElement(struct person **PersonList,int score,char *name){ void addElement(struct person *PersonList,int score,char *name){
static int size = 1; static int size = 1;
PersonList = realloc(PersonList,size*sizeof(struct person)); PersonList = realloc(PersonList,size*sizeof(struct person));
PersonList[size-1]->score = score; PersonList[size-1]->score = score;
@ -27,7 +27,7 @@ int comp(const void *p1, const void *p2){
int main(){ int main(){
struct person **PersonList=(struct person **)calloc(0,sizeof(struct person*)); struct person PersonList=calloc(0,sizeof(struct person*));
char name[30]; char name[30];
int score=0; int score=0;
int c =0; int c =0;
@ -50,7 +50,7 @@ int main(){
int flag=0; int flag=0;
printf("Vysledok\n"); printf("Vysledok\n");
for(int i =0;i<c;i++){ for(int i =0;i<c;i++){
if(strcmp(PersonList[i].name,PersonList[i+1].name)!=0||flag==0){ if(strcmp(PersonList[i]->name,PersonList[i+1]->name)!=0||flag==0){
printf("%d %s\n",PersonList[i].score,PersonList[i].name); printf("%d %s\n",PersonList[i].score,PersonList[i].name);
} }