保存出问题了不知道为什么
#include "malloc.h"#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
typedef struct stu{
long num;
char name[20];
char sex[5];
float math;
float english;
float c;
float computer;
struct stu *next;
}stulink;
/******************************链表的创建*******************************/
stulink *creat()
{
system("cls");
void main_menu();
stulink *head=NULL,*last=NULL;
stulink *p;
p=(stulink *)malloc(sizeof(stulink));
printf("input the number:");
scanf("%ld",&p->num);
printf("input the name:");
scanf("%s",p->name);
printf("input the sex:");
scanf("%s",p->sex);
p->next=NULL;
while (p->num!=0)
{
if (head==NULL)
{
head=p;
last=p;
}
else
{
last->next=p;
last=p;
}
p=(stulink *)malloc(sizeof(stulink));
printf("input the number");
scanf("%ld",&p->num);
if (p->num)
{
printf("input the name:");
scanf("%s",p->name);
printf("input the sex ");
scanf("%s",p->sex);
p->next=NULL;
}
}
system("cls");
main_menu();
return head;
}
/******************************************保存*********************************************************/
void save(stulink *head)
{
FILE *fp;
stulink *p;
p=head;
fp=fopen("d:\\mama.txt","wb");
if(fp==NULL)
{
printf("保存失败");
return;
}
while(head)
{
fwrite(p,sizeof(struct stulink*),1,fp);
p=p->next;
}
fclose(fp);
printf("保存成功");
}
void load(stulink *head)
{
FILE *fp;
stulink *p;
fp=fopen("d:\\mama.txt","rb");
if(fp==NULL)
{
printf("读取数据失败");
return;
}
while(feof(fp))
{
;
}
}
/***************************全部的遍历*******************************************************************/
void printlink(stulink *head)
{
system("cls");
void main_menu();
stulink *p;
p=head;
int a;
if(head==NULL)
{
printf("暂无信息!\n");
goto loop;
}
while(p)
{
puts("姓名\t数学\t计算机\tC语言\t英语");
printf("%s\t%.1f\t%.1f\t%.1f\t%.1f\n",p->name,p->math,p->computer,p->c,p->english);
p=p->next;
}
loop:
printf("按Q回到菜单\n");
if (getch()=='q')
main_menu();
}
/****************************成绩的遍历*******************************************************************/
void scoreinput(stulink *head)
{
system("cls");
void main_menu();
stulink *p;
p=head;
while(p)
{
printf("%s\t\n",p->name);
printf("math:");
scanf("%f",&p->math);
printf("computer:");
scanf("%f",&p->computer);
printf("c:");
scanf("%f",&p->c);
printf("english:");
scanf("%f",&p->english);
p=p->next;
}
save(head);
main_menu();
}
/*************************************************目录区***********************************************/
void main_menu()
{
system("cls");
puts("1学生信息录入");
puts("2学生成绩录入");
puts("3课程信息录入");
puts("4查询");
puts("5统计");
puts("0退出");
}
void search_menu(stulink *head)
{
puts("1全部信息现实");
puts("2按学号查询");
puts("3按姓名查询");
puts("4");
puts("5");
int option;
while(1)
{
printf("请输入序号");
scanf("%d",&option);
switch (option)
{
case 0:break;
case 1:printlink(head);break;
case 2:break;
case 3:break;
case 4:break;
case 5:break;
}
}
}
void tongji(stulink *head)
{
puts("1各科平均分");
puts("2学生平均分");
puts("3不及格学生");
puts("4");
puts("5");
int option;
while(1)
{
printf("请输入序号");
scanf("%d",&option);
switch (option)
{
case 0:break;
case 1:;break;
case 2:break;
case 3:break;
case 4:break;
case 5:break;
}
}
}
/*******************************************************************************************************/
void pinjun(stulink *head)
{
stulink *p;
p=head;
float mathsum=0.0,csum=0.0,comsum=0.0,engsum=0.0;
while(p)
{
mathsum+=p->math;
csum+=p->c;
comsum+=p->computer;
engsum+=p->english;
}
}
void main ()
{
int option;
stulink *head=NULL;
main_menu();
while(1)
{printf("请输入序号");
scanf("%d",&option);
switch (option)
{
case 0:exit(0);
case 1:head=creat();break;
case 2:scoreinput(head);break;
case 3:break;
case 4:search_menu(head);break;
case 5:tongji(head);break;
}
}
}
/*******************************************************************************************************/