| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 410 人关注过本帖
标题:求帮忙看一下哪里错了啊
取消只看楼主 加入收藏
诀珥
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-9-25
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
求帮忙看一下哪里错了啊
#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;
}

这是公交路线的程序,但是本人新手,链表总是有问题
搜索更多相关主题的帖子: include next station 公交路线 distance 
2012-09-25 20:38
快速回复:求帮忙看一下哪里错了啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045905 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved