|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct student
{
int room;
char name[100];
int score;
};
void intpustudent(struct student *intp,int leng); //输入学生信息
void sortstudent(struct student *sort,struct student *temp,int lang);//学生的排序
void outputstudent(struct student *outp,int pleg);//输出学生信息
int main()
{
struct student *parr;
struct student temp;
int len;
printf("请输入学生个数\nlen=");
scanf("%d",&len);
parr=(struct student *)malloc(len*(sizeof(struct student))); //创建动态内存然后赋给parr
intpustudent(parr,len);
sortstudent(parr,&temp,len);
outputstudent(parr,len);
return 0;
}
void sortstudent(struct student *sort,struct student *temp,int lang) //排序方法是冒泡!
{
int j,k;
for(j=0;j<lang-1;++j)
{
for(k=0;k<lang-1-j;++k)
{
if(sort[j].score>sort[j+1].score)
{
*temp=*sort[j];
*sort[j]=*sort[j+1];
*sort[j+1]=*temp;
}
}
}
}
void intpustudent(struct student *intp,int leng)
{
int i;
for(i=0;i<leng;++i)
{
printf("请输入%d个学生的信息\n",1+i);
printf("请输入学生的班级\n");
scanf("%d",&intp[i].room);
printf("请输入学生的姓名\n");
scanf("%s",intp[i].name);
printf("请输入学生分数\n");
scanf("%d",&intp[i].score);
printf("\n");
}
}
void outputstudent(struct student *outp,int pleg)
{
int j;
for(j=0;j<pleg;++j)
{
printf("输出学生的班级");
printf("%d\n",outp[j].room);
printf("输出学生的姓名");
printf("%s\n",outp[j].name);
printf("输出学生的分数");
printf("%d\n",outp[j].score);
}
}
//printf("%d",sizeof(st));
错误问题
|
|