Any code, that puts 4-2 values to order?
I´v almost finished my game, but I need a code, that puts the scores to order. Any help?
What are "4-2 values" ?
Sorry for being quiet so long, but I mean like 4 changers. unsigned short int score1, score2, score3 and score 4.
You should put the scores in an array, then you could use qsort.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <stdlib.h> /* For qsort */
typedef unsigned short Score_t;
Score_t score[4];
int comp( void *a, void *b )
{
return( (int) ( *(Score_t*)a - *(Score_t*)b ) );
}
...
qsort( score, 4, sizeof(Score_t*), comp );
...
| |
This sorts lowest into score[0].
To put highest there, switch a and b in comp().
Sorry I couldn't test it. Let me know if it doesn't work.
Topic archived. No new replies allowed.