学生管理系统 排序问题

来源:百度知道 编辑:UC知道 时间:2024/06/13 13:37:47
主函数是
void main()/*系统主函数*/
{int i;
system("cls");
struct studentinfo stu[N];
do{printf("********************************************************\n");
printf(" 学生成绩管理系统 \n");
printf("********************************************************\n");
printf("1.成绩录入\n");
printf("2.成绩查找\n");
printf("3.成绩按规定条件排序\n");
printf("4.打印成绩表\n");
printf("5.退出系统\n");
printf("请输入1~4选择功能:");
scanf("%d",&i);
switch(i)
{case 1:{system("cls");inputinfo(stu);}break;
case 2:{system("cls");findinfo(stu);}break;/* findinfo(_) */
case 3:{system("cls");sortinfo(stu);}break;/* sortinfo(_) */
case 4:{system("cls");printinfo(stu);}break;/* printinfo(_)

因为内存块不能使用t=p[i];
---------------------
void fun4(struct studentinfo *p[])/*按姓名排序函数*/
{int i,j;
struct studentinfo t; //是一个块 不能是指针
for(i=0;i<N-1;i++)
for(j=i+1;j<N;j++)
if(strcmp(p[j]->name,p[j+1]->name)<0)
{memcpy(&t,&p[j],sizeof(t)); //只有使用内存复制
memcpy(&p[j],&p[j+1],sizeof(t));
memcpy(&p[j+1],&t,sizeof(t));

}
printf("\n排序完毕\n\n");
system("pause");
system("cls");
}

我这里有个完整的程序,给你做参考吧
/************************************************************************

C 课程设计程序
学生成绩管理系统

文件名 :totall.cpp
作者 :**********
版本 : 0.5
建立日期:2005年7月

修改日期:2008年11月
定义TC3作为编译器的选择项,如果定义则选择用TUBOBC 3编译,否则用VC编译。
;****************************************************************************************
****************************************************************