/*---------------------------------------
Example 7.19
Enter the student ID, name, and score of N students in descending order.
P points to the struct variable S1, and s1. member name, (* P). Member name, p-> member name is equivalent.
It is more appropriate to use user-defined functions in this question.
Author: emanlee, eman_lee@hotmail.com
Date: 2008-05-12
---------------------------------------*/
# Include "stdio. H"
# Include "conio. H"
# Include "math. H"
# Include <string. h>
# Define N 2
Struct student
{
Int num;
Char name [12];
Int score;
};
Main ()
{
Struct student s [N];
Struct student * P, * Q [N];
Int I, J, K;
Printf ("input % d student's num name Score \ n", N );
P = s;
For (I = 0; I <n; I ++)/* input */
{
Scanf ("% d % S % d", & P-> num, p-> name, & P-> score );
Q [I] = P ++;
}
For (I = 0; I <N-1; I ++)/* select sort */
{
K = I;
For (j = I + 1; j <n; j ++)
If (Q [k]-> score <q [J]-> score)
K = J;
If (K! = I)
{
P = Q [I];
Q [I] = Q [k];
Q [k] = P;
}
}
Printf ("number name Score \ n");/* output */
For (I = 0; I <n; I ++)
Printf ("%-8d %-12 S %-d \ n", Q [I]-> num, Q [I]-> name, Q [I]-> score );
Getchar ();
}
/*--------------------------------------*/