我把全部程序贴出来大家帮忙看一下把,谢谢了,
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
xxwh();
int write();
void display( struct student *stu, int i );
void insert( struct student *stu, struct student *stu2, int count );
void del( struct student *stu, struct student *stu1, int count );
void rewrite(struct student *stu, int i);
main_menu();
struct student
{
char name[20];
int xh;
int chi;
int math;
int eng;
double average;
};
int write()
/*录入函数*/
{int xh,eng,chi,math, i = 1;
char name[64],res[1024];
FILE *fp;
if ((fp=fopen("d:\\file.txt", "w+")) == 0) {
printf("无法创建文件..\n");
exit(1);
}
printf("输入第%d个同学姓名(返回菜单请输入exit): ", i);
scanf("%s", name);
while (strcmp(name, "exit") != 0) {
printf("学号:");
scanf("%d", &xh);
printf("语文:");
scanf("%d", &chi);
printf("数学:");
scanf("%d", &math);
printf("英语:");
scanf("%d", &eng);
sprintf(res, "name: %s, xh: %d, eng: %d, chi: %d, math: %d\n", name, xh, eng,chi,math);
fputs(res, fp);
printf("输入第%d个同学姓名(返回菜单请输入exit): ", ++i);
scanf("%s", name);
}
fclose(fp);
main_menu();
return 0;}
void display( struct student *stu, int i )
/*显示函数*/
{
printf("学号\t姓名\t平均成绩\n");
while ( i > 0 )
{
printf("%d\t%s\t%.2f\n", stu->xh , stu->name, stu->average );
i--;
stu++;
}
}
void insert( struct student *stu, struct student *stu2, int count )
/*插入函数*/
{
int i;
int j;
struct student stu1;
printf("请输入要插入的学员信息:\n");
printf("学号:");
scanf("%d", &stu1.xh);
printf("姓名:");
fflush(stdin);
gets(stu1.name);
printf("三门成绩:\n\n");
printf("语文:");
scanf("%d", &stu1.chi );
printf("数学:");
scanf("%d", &stu1.math );
printf("英语:");
scanf("%d", &stu1.eng );
(stu1.average) = ((stu1.chi+stu1.math+stu1.eng)/3.0);
for ( i = 0; i < count; i++ )
{
if ( stu1.average > (stu+i)->average )
{
for ( j = count; j>i; j-- )
{
*(stu+j) = *(stu+j-1);
}
*(stu+j) = stu1;
}
}
printf("插入新学员后的学员信息如下");
display( stu2, ++count);
}
void del( struct student *stu, struct student *stu1, int count )
/*删除函数*/
{
int delxh;
int i;
int j;
printf("请输入要删除的学员的学号:");
scanf("%d", &delxh);
for ( i = 0; i < count; i++ )
{
if ( delxh == (stu+i)->xh )
{
for ( j = i; j < count; j++ )
{
*(stu + j) = *(stu + j + 1);
}
}
}
printf("删除后的学员信息如下:\n");
display( stu1, count);
}
void rewrite(struct student *stu, int i)
{
int k;
int q;
printf("\n\t\t请输入要修改的学生学号:");
scanf("%s",q);
for(k=0;k<99999;k++)
{
if(stu[i].xh==q)
{
printf("\n\t\t以下是您要修改的学生纪录:");
printf("\n\t\t________________________________");
printf("\n\t\t学号:
%s",stu[i].xh);
printf("\n\t\t姓名:
%s",stu[i].name);
printf("\n\t\t语文:
%s",stu[i].chi);
printf("\n\t\t数学:
%s",stu[i].math);
printf("\n\t\t英语:
%s",stu[i].eng);
printf("\n\t\t________________________________");
printf("\n\t\t请输入修改后的学生信息:");
printf("\n\t\t输入姓名:");
scanf("%s",&stu[i].name);
printf("\n\t\t输入学号:");
scanf("%s",&stu[i].xh);
printf("\n\t\t输入语文成绩:");
scanf("%s",&stu[i].chi);
printf("\n\t\t输入数学成绩:");
scanf("%s",&stu[i].math);
printf("\n\t\t输入英语成绩:");
scanf("%s",&stu[i].eng);
printf("\n\t\t是否继续修改?(Y/N):");
if (getchar()=='y')
{
void rewrite();
}
return;
}
}
printf("\n\t\t没有改学生的信息");
printf("\n\t\t按任意键返回主菜单");
getchar();
return;
}
main_menu()
{
int i=0;
printf("
******
成绩管理系统
******
\n");
printf("\n1:信息维护\t
2: 信息查询\n");
printf("\n3:成绩系统\t
4: 退出\n");
printf("************************************\n");
printf("\n按数字输入选择:");
scanf("%d",&i);
while(i!=0)
{
switch(i)
{
case 1:xxwh();break;
}
}
}
xxwh()
{
int a=0;
printf("1:录入学生信息\n");
printf("2:增加学生信息\n");
printf("3:删除学生信息\n");
printf("4:修改学生信息
\n");
printf("5:返回\n");
printf("***************
信息维护
*******************\n");
printf("\n按数字选择输入:");
scanf("%d",&a);
while(a!=0)
{
switch(a)
{
case 1:write();break;
case 2:{void insert(struct student *stu, struct student *stu2, int count);}break;
case 3:{void del( struct student *stu, struct student *stu1, int count );break;}
case 4:{void rewrite(struct student *stu, int i);break;}
default: printf("\n输入错误重新选择");main_menu();break;
}
}
}
int main()
{
main_menu();
}