Current location - Training Enrollment Network - Mathematics courses - Structure array as parameter
Structure array as parameter
This can: put the structure definition outside main.

# include & ltstdio.h & gt/* stu, a structural variable, contains the student's student number, the names and scores of three courses. You need to assign an initial value in main and print it out in the function print */

void print(struct stu *s,int I);

Struct cj/* the results of three courses */

{

Within Yu Wen;

Int calligraphy;

Within Yu Ying;

}cj[3]={ {80,90, 100},{70,7 1,72},{60,6 1,62 } };

Structure stu/* students */

{

int num

char name[20];

Structural cj score;

}stu 1[3]={

{1, "one", cj[0]. Yu Wen, cj[0]. Shu Xue, cj[0]. Yu Ying},

{2, "two", cj[ 1]. Yu Wen, cj[ 1]. Shu Xue, cj[ 1]. Yu Ying},

{3, "three", cj[2]. Yu Wen, Chief Justice [2]. Shu studies, cj[2]. Yu Ying}

};

int main()

{

int I;

Printf ("Enter Student ID \ n");

scanf("%d ",& ampI);

Print (& ampstu 1[i-1], i);

getchar();

}

Invalid printing (structure stu *s, int i)

{

int n;

printf("%d,%s,%d,%d,%d\n ",s-& gt; num,s-& gt; Name, cj[i-1]. Yu Wen, cj[i-1]. Shu Xue, cj[i-1]. Yu Ying);

}