Dynamic Structure of struct Array
# Include <stdio. h> # include <malloc. h> struct student {int age; float score; char name [100] ;}; int main (void) {int Len; struct student * Parr; int I, J; struct Student t; // dynamically construct a one-dimensional array printf ("Enter the number of students: \ n"); printf ("Len ="); scanf ("% d ", & Len); Parr = (struct student *) malloc (LEN * sizeof (struct student); // input for (I = 0; I <Len; ++ I) {printf ("Enter % d student information: \ n", I + 1); printf ("age ="); scanf ("% d ", & Parr [I]. age); printf ("name ="); scanf ("% s", Parr [I]. name); // name is the array name, which is already the address of the first element of the array, so Parr [I]. name cannot be changed to & Parr [I]. name printf ("score ="); scanf ("% F", & Parr [I]. score);} // sort by Student Score ascending bubble Algorithm for (I = 0; I <len-1; ++ I) {for (j = 0; j <len-1-i; ++ J) {If (Parr [J]. score> Parr [J + 1]. score) //> ascending <descending {T = Parr [J]; Parr [J] = Parr [J + 1]; parr [J + 1] = T ;}} printf ("\ n student information: \ n"); // output for (I = 0; I <Len; ++ I) {printf ("% d student information: \ n", I + 1 ); printf ("age = % d \ n", Parr [I]. age); printf ("name = % s \ n", Parr [I]. name); // name is the array name, which is already the address of the first element of the array, so Parr [I]. name cannot be changed to & Parr [I]. name printf ("score = % F \ n", Parr [I]. score); printf ("\ n");} return 0 ;}