#include<stdio.h>
#include<stdlib.h>
typedef struct stu{
char name[20];
int num;
int score;
};
void sr(int n,stu st[]) //学生数据输入
{
int i;
for(i=0;i<n;++i)
{
printf("请输入第%d个学生的信息\n",i+1);
scanf("%s\n%d\n%d",&st[i].name,&st[i].num,&st[i].score);
}
};
void sc(int n,stu st[]) //学生数据输出
{
int i;
for(i=0;i<n;++i)
{
printf("名字:%s\n学号:%d\n成绩:%d\n",st[i].name,st[i].num,st[i].score);
};
}
void main()
{ int n;
stu *st;
printf("请输入寝室人数");
scanf("%d",&n);
st= (stu *)malloc(n *sizeof(stu));
sr(n,st);
sc(n,st);
free(st);
st=NULL;
system("pause");
}
新手编写,
如有错误 望指出