Im writing a program which is using qsort from stdlib.h. My code is working but im wondering why I dont have to declare anything in the prototype for my comparsion function.
My prototype for my comparisonfunction is:
int comparePoints();
My qsort call is:
qsort(holdarray, NumbersOfTeams, sizeof(struct hold), comparePoints);
My comparison function is:
int comparePoints(void *a, void *b, void *c, void *d){
int team1P, team2P, team1G, team2G;
team1P = ((struct hold *)a)->points;
team1G = ((struct hold *)c)->goalscored;
team2P = ((struct hold *)b)->points;
team2G = ((struct hold *)d)->goalscored;
if (team1P>team2P){
return -1;
}
if (team1P == team2P){
if (team1G > team2G)
{
return -1;
}else
{
return 1;
}
}
else{
return 1;
}
}
Hope one of you can enlighten me!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…