I want to know this situation.
when I define this sentence
struct soccer team[100] ;
I can do qsort ;
qsort(team, MAX , sizeof(team[0]) , compare) ;
int compare(const void *a, const void *b )
{
SOC *A1 = (SOC*)a ;
SOC *B1 = (SOC*)b ;
if( A1->score > B1->score )
return -1 ;
else if ( A1->score == B1->score )
return 0 ;
else
return 1 ;
}
When I do dynamic allocation
struct soccer*team[MAX] ;
team[Index] = (SOC*)malloc(sizeof(SOC)) ;
error is existed. (qsort and compare is same )
I want to know how do use it(qsort for dynamic allocation struct)
please!
example ( when I use first way)
Man 3 1 1 16
Che 2 2 2 8
Asn 0 6 0 6
hot 6 0 0 18
City 0 0 6 0
Bar 1 5 0 8
is converted
hot 6 0 0 18
Man 3 1 1 16
Che 2 2 2 8
Bar 1 5 0 8
Asn 0 6 0 6
City 0 0 6 0