構造体配列へのポインタ学習ノート
#include<stdio.h>
void main()
{
struct stu_type{
char num[15];
char name[10];
int age;
int c;
int math;
int en;
int sum;
float ave;
}*p,stu[3]= {{"2011110101"," ",22,60,70,75},
{"2011110102"," ",22,65,75,75},
{"2011110103"," ",21,68,78,75}};
printf(" \t \t \tC \t \t \t \t
");
for(p=stu;p<stu+3;p++)
{
p->sum = p->c + p-> math + p-> en;
p->ave = (float)p->sum/3;
printf("%-16s%s\t%d\t%d\t%d\t%d\t%d\t%5.1f
",p->num,p->name,p->age,p->c,p->math,p->en,p->sum,p->ave) ;
}
}