我这个程序在对学号排序的时候老是显示乱码,谁能帮我看一下
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#include <string.h>
#define STUDENT_NUMBER_MAX 100
int m=0,f=0,t;
typedef struct ST{
long int Sno;
char Sname[10];
char Ssex[10];
int Sage;
int mathematics;
int English;
int program_design;
}Student;
void Insert(Student Student[]) //添加学生信息
{
int n,l;
printf("请输入要添加的学生人数:");
scanf("%d",&n);
m=m+n;
for(;f<m;f++)
{
printf("请输入第%d位学生学号,姓名,性别,年龄,数学成绩,英语成绩,程序设计成绩:\n",f+1);
scanf("%d%s%s%d%d%d%d",&Student[f].Sno,&Student[f].Sname,&Student[f].Ssex,&Student[f].Sage,&Student[f].mathematics,&Student[f].English,&Student[f].program_design);
for(l=0;l<m;l++)
if(Student[l].Sno==Student[f].Sno&&l!=f)
{
printf("\n对不起,此学号已存在ˇ_ˇ\a\n");
m--;f--;
}
}
}
void delecte(Student Student[]) //删除学生信息
{
int k,num;
if(m!=0)
{
printf("请输入要删除的学生人数:");
scanf("%d",&k);
while(k)
{
int n=0;
printf("请输入要删除的学生学号:");
scanf("%d",&num);
while(Student[n].Sno!=num&&n<m){
n++;
}
if(n>=m)
printf("\n对不起,没有学生信息!\a\n");
else for(;n<=m;n++)
{
Student[n].Sno=Student[n+1].Sno;strcpy(Student[n].Sname,Student[n+1].Sname);strcpy(Student[n].Ssex,Student[n+1].Ssex);Student[n].Sage=Student[n+1].Sage;Student[n].mathematics=Student[n+1].mathematics;Student[n].English=Student[n+1].English;Student[n].program_design=Student[n+1].program_design;
}
m--;f--;k--;
}
}
else printf("对不起,没有学生信息!\a\n\n");
}
void Statistics(Student Student[]) //统计学生信息
{
if(m!=0){
int boy=0,girl=0,i;
int mathsun=0,Engsun=0,prosun=0,mathave=0,Engave=0,proave=0;
printf("学生总数为%d\n",m);
for(i=0;i<m;i++)
{
if(strcmp(Student[i].Ssex,"男")==0)
boy++;
else girl++;
mathsun=mathsun+Student[i].mathematics;
Engsun=Engsun+Student[i].English;
prosun=prosun+Student[i].program_design;
}
printf("男生人数为:%d\n",boy);
printf("女生人数为:%d\n",girl);
printf("数学总成绩为:%d\n",mathsun);
printf("英语总成绩为:%d\n",Engsun);
printf("程序设计总成绩为:%d\n",prosun);
printf("数学平均成绩为:%d\n",mathsun/m);
printf("英语平均成绩为:%d\n",Engsun/m);
printf("程序设计平均成绩为:%d\n",prosun/m);
}
else printf("\n没有学生信息!\a\n");
}
void save(Student Student[]) //保存学生信息
{
int i;
FILE *fp;
if((fp=fopen("学生管理系统","wb"))==0)
printf("ERROR!");
for(i=0;i<m;i++)
fwrite(&Student[i],sizeof(struct ST),1,fp);
printf("\n保存成功!\n");t=m;
fclose(fp);
}
void read(Student Student[]) //读取学生信息
{
int i;
FILE *fp;
if((fp=fopen("学生管理系统","rb"))==0)
printf("\n文件不存在!\a\n");
printf("-----------------------------------学生信息----------------------------------\n\n");
printf("学号\t\t姓名\t 性别\t年龄\t数学成绩 英语成绩 程序设计成绩\n\n");
for(i=0;i<t;i++)
printf("%-16d%-10s%-6s%-10d%-13d%-10d %-10d\n",Student[i].Sno,Student[i].Sname,Student[i].Ssex,Student[i].Sage,Student[i].mathematics,Student[i].English,Student[i].program_design);
fclose(fp);
}
void updata(Student Student[]) //修改学生信息
{
int num,n=0;
if(m!=0){
printf("\n请输入要修改的学生学号: ");
scanf("%d",&num);
while(Student[n].Sno!=num&&n<m){
n++;
}
if(n>=m)
printf("\n对不起,没有此学生的信息!\a\n");
else
{
printf("请修改此学生的学号,姓名,性别,年龄,数学成绩,英语成绩,程序设计成绩:\n");
scanf("%d%s%s%d%d%d%d",&Student[n].Sno,&Student[n].Sname,&Student[n].Ssex,&Student[n].Sage,&Student[n].mathematics,&Student[n].English,&Student[n].program_design);
}
printf("\n修改成功!\n");
}
printf("\n没有学生信息!\a\n");
}
void display(Student Student[]) //显示学生信息
{
int i;
if(m!=0){
printf("-----------------------------------学生信息----------------------------------\n\n");
printf("学号\t\t姓名\t 性别\t年龄\t数学成绩 英语成绩 程序设计成绩\n\n");
for(i=0;i<m;i++)
printf("%-16d%-10s%-6s%-10d%-13d%-10d %-10d\n",Student[i].Sno,Student[i].Sname,Student[i].Ssex,Student[i].Sage,Student[i].mathematics,Student[i].English,Student[i].program_design);
}
else printf("对不起,没有学生信息!\a\n");
}
void snosequence(Student Student[]) //排序学生信息
{
int j,k;
int Sno1,Sno2;
char Sname[20];
char Ssex[10];
int mathematics,program_design,English,Sage;
for(j=0;j<m;j++)
for(k=0;k<m-j;k++)
if(Student[k].Sno>Student[k+1].Sno)
{
Sno1=Student[k].Sno;Sno2=Student[k+1].Sno;Student[k+1].Sno=Sno1;Student[k].Sno=Sno2;
//strcpy(Sname,Student[k].Sname);strcpy(Student[k].Sname,Student[k+1].Sname);strcpy(Student[k+1].Sname,Sname);
//strcpy(Ssex,Student[k].Ssex);strcpy(Student[k].Ssex,Student[k+1].Ssex);strcpy(Student[k+1].Ssex,Ssex);
//Sage=Student[k].Sage;Student[k].Sage=Student[k+1].Sage;Student[k+1].Sage=Sage;
//mathematics=Student[k].mathematics;Student[k].mathematics=Student[k+1].mathematics;Student[k+1].mathematics=mathematics;
//English=Student[k].English;Student[k].English=Student[k+1].English;Student[k+1].English=English;
//program_design=Student[k].program_design;Student[k].program_design=Student[k+1].program_design;Student[k+1].program_design=program_design;
}
}
int main()
{
printf(" 沈阳农业大学科学技术学院学生管理系统 V1.0\n\n\n");
Student student[STUDENT_NUMBER_MAX],*p,S;
p=student;
int c;
while(c!=0)
{
printf("————————————————主菜单———————————————————\n");
printf(" 1.添加学生信息. \n");
printf(" 2.删除学生信息. \n");
printf(" 3.修改学生信息. \n");
printf(" 4.查看学生信息. \n");
printf(" 5.统计学生信息. \n");
printf(" 6.保存学生信息. \n");
printf(" 7.读取学生信息. \n");
printf(" 8.排序学生信息. \n");
printf(" 0.退出. \n");
printf("请选择菜单: ");
scanf("%d",&c);
switch(c)
{
case 1: Insert(p);break;
case 2: delecte(p);break;
case 3: updata(p);break;
case 4: display(p);break;
case 5: Statistics(p);break;
case 6: save(p);break;
case 7: read(p);break;
case 8: snosequence(p);break;
}
if(c!=1&&c!=2&&c!=3&&c!=4&&c!=0&&c!=5&&c!=6&&c!=7&&c!=8)
printf("\n ERROE!\n");
}
return 0;
}