Dynamic Structure of struct Array

Source: Internet
Author: User

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.