Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

Prototypes for qsort in C

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...