c语言指针赋值和地址赋值,关于指针结构体地址赋值的问题

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

int grad,clas;

struct stu_

{

char name[11];

char sex;

int num;

float score[3];

float ave;

}; void input(struct stu_ *p)

{

int j;

printf("请输入姓名:");

gets(p->name);

printf("请依次输入性别-学号:");

scanf("%c-%d",&p->sex,&p->num);

printf("请依次输入数学 语文 英语成绩:\n");

for(j=0;j<3;j++)

scanf("%f",&p->score[j]);

} void ave(struct stu_ *p)/*……*/ {

int j;

p->ave=0;

for(j=0;j<3;j++)

p->ave+=p->score[j]/3.0;

} void sort(struct stu_ *p,int n)

{

struct stu_ *t;

int i,j; for(i=0;i

{

for(j=0;j

{

if( (p+j+1)->ave > (p+j)->ave )

{

t=(p+j+1);

// (p+j+1)=p+j;

// (p+j)=t;

}

}

}

} void output(struct stu_ *p)

{

printf("%-6s%8.1c%9.1f%8.1f%8.1f%8.1f\n",p->name,p->sex,p->score[0],p->score[1],p->score[2],p->ave);

} main()

{

struct stu_ stud[50],*p=stud,c;

int n,i;

float *q; printf("请输入年级-班级:");

scanf("%d-%d",&grad,&clas); printf( "请输入学生总数:" );

scanf( "%d",&n ); for(p=stud;p

input(p); for(p=stud;p

{

ave( p );

} for(p=stud;p

sort( p,n ); printf(" %d-%d班成绩为:\n",grad,clas);

printf("姓名 性别 数学 语文 英语 平均分\n");

for(p=stud;p

output( p ); system( "pause" );

}