By using a structure pointer output 4 students Student ID Name Gender Age

. 1 # the include <stdio.h>
 2  
. 3  / * define a global structure * / 
. 4  struct Student
 . 5  {
 . 6      Long NUM;
 . 7      char name [ 20 is ];
 . 8      char Sex;
 . 9      int Age;
 10  };
 . 11  
12 is  / * declare an array of structures and initial value * / 
13 is  struct Student STU [ . 4 ] = {{ 97 032 , " Xiao Ming " , ' M ' , 20 is },
14                          {97033, "xiao wang", 'M', 20},
15                          {97034, "xiao tong", 'M', 21},
16                          {97035, "xiao shui", 'F', 18}};
17 
18 void main()
19 {
20     /*Definition of a structure pointer variable * / 
21 is      struct Student * P;
 22 is  
23 is      the printf ( " Science No. Name Sex Age \ n- " );
 24      for (P = STU; P <STU + . 4 ; P ++ )
 25          the printf ( " % -8ld -10c -3d% -12s%% \ n- " , p-> NUM, p-> name, 
 26 is                                         p-> Sex, p-> Age);
 27 }

 

Guess you like

Origin www.cnblogs.com/liugangjiayou/p/11617358.html