求帮忙看一下哪里错了啊
#include <stdio.h>#include <stdlib.h>
#include <string.h>
char *bus_filename = "bus.dat";
char *station_filename = "station.dat";
typedef struct BUS
{
int no;
char time1[10];//首班时间
char time2[10];//末班时间
int money;
struct STATION *snext;
struct BUS *next;
} bus; //公交路线链表
typedef struct STATION
{
char name[20];
int distance;
struct STATION *next;
} station; //站点链表
bus *head=NULL;
int flag_head = 0;
int main()
{
mgraph c;
int z,m=0;
char a;
//load();
while(m==0)
{
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("9:换乘最少公交路线\n");
printf("0:保存\n");
printf("请输入要执行的步骤\n");
scanf("%d",&z);
switch(z)
{
case 1:
input();
break;
case 2:
change();
break;
case 3:
chaxun();
break;
case 4:
paixu1();
break;
case 5:
paixu2();
break;
case 6:
chaxun2();
break;
case 7:
chaxun3();
break;
case 8:
initgraph(c);
shortestpath_dij(c);
break;
case 9:
lujin();
break;
case 0:
save();
break;
default:
printf("输入有误\n");
}
printf("是否退出程序(y/n)\n");
scanf("%s",&a);
if((a=='y')||(a=='Y'))
m=1;
else m=0;
}
return 0;
}
int input()//输入函数
{
station *p=NULL,*e=NULL;
bus *q=NULL,*hp=head;
int a=1,b=1;
char n,m;
while(b==1)
{
while(hp!=NULL)
{
hp=hp->next;
}
q=(bus*)malloc(sizeof(bus));
printf("请输入公交路线名\n");
scanf("%d",&q->no);
printf("请输入首班车时间\n");
scanf("%s",q->time1);
printf("请输入末班车时间\n");
scanf("%s",q->time2);
printf("请输入票价(单位:元)\n");
scanf("%d",&q->money);
hp=q;
if( 0 == flag_head)
{
head = q;
flag_head = 1;
}
hp->next=NULL;
p=(station*)malloc(sizeof(station));
q->snext=p;
printf("请输入起点站的名称\n");
scanf("%s",p->name);
p->distance=0;
p->next = NULL;
a=1;
while(a==1)
{
e=(station *)malloc(sizeof(station));
printf("请输入下一站的名字\n");
scanf("%s",e->name);
printf("请输入离上一站的距离(单位:米)\n");
scanf("%d",&e->distance);
p->next=e;
p=p->next;
printf("是否继续输入车站?(Y/N)\n");
scanf("%s",&n);
if(n=='y')
a=1;
else a=0;
}
p->next=NULL;
printf("输入完成");
printf("是否继续输入(y/n)\n");
scanf("%s",&m);
if(m=='y')
b=1;
else b=0;
}
return 0;
}
int save()
{
bus *q=NULL;
station *p=NULL;
FILE * pfout;
if ((pfout = fopen(bus_filename,"wb"))==NULL)
{
exit(-1);
}
for(q=head; q!=NULL; q=q->next)
{
fwrite(q,sizeof(bus),1,pfout);
}
fclose(pfout);
if((pfout=fopen(station_filename,"wb"))==NULL)
{
exit(-1);
}
for(q=head; q!=NULL; q=q->next)
{
p=q->snext;
while(p!=NULL)
{
fwrite(p,sizeof(station),1,pfout);
p=p->next;
}
}
fclose(pfout);
printf("操作成功!!!\n");
getchar();
return 0;
}
int load()
{
FILE *fp1;
FILE *fp2;
bus *hp=NULL, *p=head;
station *q=NULL,*pp1=NULL;
if((fp1=fopen("bus.dat","rb"))==NULL)
exit(-1);
if((fp2=fopen("station.dat","rb"))==NULL)
exit(-1);
p=(bus *)malloc(sizeof(bus));
fread(p, sizeof(bus), 1, fp1);
p->snext=NULL;
hp=p;
head=hp;
while(!feof(fp1))
{
p=(bus *)malloc(sizeof(bus));
fread(p, sizeof(bus), 1, fp1);
hp->next=p;
p->snext=NULL;
hp=p;
}
p=head;
q=(station *)malloc(sizeof(station));
fread(q,sizeof(station),1,fp2);
while(!feof(fp1))
{
p->snext=q;
pp1=q;
q=(station *)malloc(sizeof(station));
fread(q,sizeof(station),1,fp2);
while(!(q->distance==0))
{
pp1->next=q;
pp1=q;
q=(station *)malloc(sizeof(station));
fread(q,sizeof(station),1,fp2);
}
p=p->next;
}
printf("载录完成\n");
fclose(fp1);
fclose(fp2);
return 0;
}
这是公交路线的程序,但是本人新手,链表总是有问题