| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2936 人关注过本帖
标题:运用链表的程序,我估计是output()和foutput()错了,但是不知道错哪了。。
取消只看楼主 加入收藏
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
结帖率:0
收藏
已结贴  问题点数:20 回复次数:13 
运用链表的程序,我估计是output()和foutput()错了,但是不知道错哪了。。
编译可以通过,运行可以看到主界面,但是输入选择会[local]1[/local]


程序如下:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <windows.h>
void system_time();void load();void add();void search();void buy_ticket();void back_ticket();void output();void foutput();void search1();void search2();//申明函数
struct time
{
    int hour;
    int minute;
};
struct Ticket
{
    char number[100];//班次
    struct time ft;//列车出发时间
    char origin_station;//起始站
    char last_station[100];//终点站
    float last_time;//行车时间
    int max_number;//额定载量
    int sold_ticket;//已订票人数
    char condition[100];//状态
    struct Ticket*next;
};
int i;                        
int syshour;                    //记录系统时间小时     
int sysminute;                  //记录系统时间分钟   
char filename[100];              //文件名数组                     
int record;                     //记录条数记录

struct Ticket *head,*end,*p,*q;//全局变量,方便后面的使用
void main()
{
    int z;
    z=0;
    printf("当前时间:");
    system_time();
    printf("*******************************************\n");
    printf("            欢迎使用车票管理系统           \n");
    printf("                1.录入车票信息             \n");
    printf("                2.单个添加车次信息         \n");
    printf("                3.浏览班次信息             \n");
    printf("                4.查询路线                 \n");
    printf("                5.购票                     \n");
    printf("                6.退票                     \n");
    printf("                0.退出程序                 \n");
    printf("*******************************************\n");
    printf("请输入您想做的操作:");
    scanf("%d",&z);
    switch(z)
    {
        case 1:load();break;
        case 2:add();break;
        case 3:output(head);break;
        case 4:search();break;
        case 5:buy_ticket();break;
        case 6:back_ticket();break;
        case 7:back_ticket();break;
        case 0:break;
        default :printf("选择错误!!!");
    }
    printf("感谢您的使用!!!\n");
    }
    void system_time()
    {
        SYSTEMTIME sys;
        GetLocalTime( &sys );                //调用系统时间
        printf( "%4d /%02d/%02d %02d:%02d:%02d 星期%1d\n",
                 sys.wYear,
                 sys.wMonth,
                 sys.wDay,
                 sys.wHour,
                 sys.wMinute,
                 sys.wSecond,
                 sys.wDayOfWeek);
                 syshour=sys.wHour;            
                 sysminute=sys.wMinute;
    }
   
   
    void output(struct Ticket *head1)
    {
       struct Ticket *q;//建立量表的函数
       printf("班次\t时间\t起始站\t终点站\t行车时间\t额定载量\t已订票人数\t状态\n");
       q=head1->next;
       while(q!=NULL)
       {
              printf("%s\t%02d:%02d\t%s\t%s\t%f\t%d\t%d\t%s\n",q->number,q->ft.hour,q->ft.minute,q->origin_station,q->last_station,q->last_time,q->max_number,q->sold_ticket,q->condition);
           q=q->next;
           if((syshour>q->ft.hour)||((syshour==q->ft.hour) &&(sysminute>q->ft.minute)))
           printf("已发出\n",q->condition);
           else
           printf(" \n",q->condition);
       }
    }

    void foutput(struct Ticket *head1)
    {
        FILE*fp1;
        struct Ticket *q;
        fp1=fopen("车票班次信息.txt","w");
        if(fp1==NULL)
        {
            printf("无法打开文件!\n");
            exit(0);
        }
        q=head->next;
        while(q!=NULL)
        {
            fprintf(fp1,"%s\t%02d:%02d\t%s\t%s\t%f\t%d\t%d\n",q->number,q->ft.hour,q->ft.minute,q->origin_station,q->last_station,p->last_time,q->max_number,q->sold_ticket,q->condition);
            q=q->next;
        }
        fclose(fp1);
    }
     void load()
    {
        FILE*fp;
        fp=fopen("车票班次信息.txt","r");
        if(fp==NULL)
        {
            printf("无法打开文件");
            exit(0);
        }
        head=(struct Ticket *)malloc(sizeof(struct Ticket));
        end=head;
        end->next=NULL;
        while(!feof(fp))
        {
            p=(struct Ticket *)malloc(sizeof(struct Ticket));
            fscanf(fp,"%s%d:%02d%s%s%f%d%d\n",&p->number,&p->ft.hour,&p->ft.minute,&p->origin_station,&p->last_station,&p->last_time,&p->max_number,&p->sold_ticket,&p->condition);
            p->next=NULL;
            end->next=p;
            end=p;
        }
        output(head);
        fclose(fp);
    }
    void add()
    {
        load();
        p=(struct Ticket *)malloc(sizeof(struct Ticket));
        printf("请输入您要增加的班次:");
        scanf("%s",&p->number) ;
        printf("请输入您要增加的班次的出发时间:");
        scanf("%d:%02d",&p->ft.hour,&p->ft.minute);
        printf("请输入你要增加的班次的起始站:");
        scanf("%s",&p->origin_station);
        printf("请输入您要增加的班次的终点站:");
        scanf("%s",&p->last_station);
        printf("请输入您要增加的班次的行车时间:");
        scanf("%f",&p->last_time);
        printf("请输入您要增加的班次的额定载量");
        scanf("%d",&p->max_number);
        printf("请输入您要增加的班次的已订票人数");
        scanf("%d",&p->sold_ticket);
        p->next=NULL;
        end->next=p;
        end=p;
        foutput(head);
        output(head);
    }
    void search()
    {
        int s;
        s=0;
        printf("*****************查询菜单****************\n");
        printf("             1.按班次号查询              \n");
        printf("             2.按终点站查询              \n");
        printf("             0.返回主菜单                \n");
        printf("*****************************************\n");
        printf("请输入您想要的操作:\n");
        scanf("%d\n",&s);
        switch(s)
        {
            case 1:search1();break;
            case 2:search2();break;
            case 0:output(head);
            default:printf("选择错误!!!");
        }
    }
    void search1()
    {
        struct Ticket *p;
        char number[100];
        char i;
        printf("请输入您要查询车辆的班次号:\n");
        scanf("%d",&i);
        p=head->next;
        do
        {
            if(strcmp(number,p->number)==0)
            {
                printf("%s\t%d:%d\t%s\t%s\t%f\t%d\t%d\n",p->number,p->ft.hour,p->ft.minute,p->origin_station,p->last_station,p->last_time,p->max_number,p->sold_ticket);
                printf("\n\n");
            }
        
        }
            while(p!=NULL);
            printf("输入的班次号有误!");
        foutput(head);
        output(head);
    }
    void search2()
    {
        struct Ticket *p;
        char last_station[100];
        char c;
        printf("请输入您要查询车次的终点站:\n");
        scanf("%s",&c);
        p=head->next;
        do
        {
             if(strcmp(last_station,p->last_station)==0)
            {
              printf("%d\t\t%d:%d\t\t%s\t\t%s\t\t%f\t\t%d\t\t%d\n\n",p->number,p->ft.hour,p->ft.minute,p->origin_station,p->last_station,p->last_time,p->max_number,p->sold_ticket);
                printf("\n\n");
            }
           }    while(p!=NULL);
               foutput(head);
            output(head);
        
    }
    void buy_ticket()
    {
        int m,n;
        char number[100];
        m=0;
        load();
        printf("请输入您要买的班次号:\n");
        scanf("%s,number");
        p=head->next;
        while(p!=NULL)
        {
            if(strcmp(p->number,number)==0)
            {
                printf("请输入您要购买的票数:\n");
                scanf("%d",&n);
                if(p->sold_ticket=p->max_number)
                printf("您需要的车票已售空\n");
                else if (n>(p->max_number-p->sold_ticket))
                printf("您需要的班次车票不足\n");
                else if((syshour>p->ft.hour)||((syshour==p->ft.hour) &&(sysminute>p->ft.minute)))
                printf("您需要的班次车辆已发出\n");
                else
                {
                    p->sold_ticket=p->sold_ticket+n;
                    printf("订票成功\n");
                }
                m++;
                p=p->next;
            }   
         
        else if(m==0)
        printf("您输入的班次号有误!\n");
        else foutput(head);
        output(head);
        }
    }
    void back_ticket()
    {
        int m,n;
        char number[100];
        m=0;
        load();
        printf("请输入您要退票的班次\n");
        scanf("%s",number);
        p=head->next;
        while(p!=NULL)
        {
            if(strcmp(number,p->number)==0)
            {
                printf("请输入您要退还的票数\n");
                scanf("%d",&n);
                if((syshour>p->ft.hour)||((syshour==p->ft.hour) &&(sysminute>p->ft.minute)))
                printf("您退还的班次已发出,退票失败!");
                else
                p->sold_ticket=p->sold_ticket+n;
                m++;
            }
            if(m==0)
            printf("对不起,您输入的班次号错误!\n");
            else
            foutput(head);
            output(head);
        }
    }
   
搜索更多相关主题的帖子: include search number minute 
2016-04-28 14:49
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
上面的是全部的程序,这里的是output()跟foutput()
void output(struct Ticket *head1)
    {
       struct Ticket *q;//建立量表的函数
       printf("班次\t时间\t起始站\t终点站\t行车时间\t额定载量\t已订票人数\t状态\n");
       q=head1->next;
       while(q!=NULL)
       {
              printf("%s\t%02d:%02d\t%s\t%s\t%f\t%d\t%d\t%s\n",q->number,q->ft.hour,q->ft.minute,q->origin_station,q->last_station,q->last_time,q->max_number,q->sold_ticket,q->condition);
           q=q->next;
           if((syshour>q->ft.hour)||((syshour==q->ft.hour) &&(sysminute>q->ft.minute)))
           printf("已发出\n",q->condition);
           else
           printf(" \n",q->condition);
       }
    }

    void foutput(struct Ticket *head1)
    {
        FILE*fp1;
        struct Ticket *q;
        fp1=fopen("车票班次信息.txt","w");
        if(fp1==NULL)
        {
            printf("无法打开文件!\n");
            exit(0);
        }
        q=head->next;
        while(q!=NULL)
        {
            fprintf(fp1,"%s\t%02d:%02d\t%s\t%s\t%f\t%d\t%d\n",q->number,q->ft.hour,q->ft.minute,q->origin_station,q->last_station,p->last_time,q->max_number,q->sold_ticket,q->condition);
            q=q->next;
        }
        fclose(fp1);
    }
2016-04-28 14:53
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 3楼 alice_usnet
即使是改成了q->lq->lset_time,也是同样的结果,求指导
2016-04-28 15:21
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
各位大神,明天就要交程序了,如果还是不能正常运行我就要挂科了,求指教啊
2016-04-28 15:27
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 6楼 alice_usnet
改过来了,科还是不行,选择1就会是一堆乱七八糟的东西,然后结束程序
2016-04-28 15:40
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 8楼 alice_usnet
改了之后好了一些
界面显示成了
图片附件: 游客没有浏览图片的权限,请 登录注册

还是没办法运行,不过已经比我之前好了许多
2016-04-28 16:03
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 8楼 alice_usnet
能帮忙看看具体原因吗?
还有,能解释一下之前的问题吗?
先谢过
2016-04-28 16:07
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 9楼 wanglianyi1
我现在是一些细节问题,你给我一个程序参考也没什么用啊
2016-04-28 16:09
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 13楼 alice_usnet
这次能运行了,结果如下:
图片附件: 游客没有浏览图片的权限,请 登录注册


真的对不起,我的C是自学的,真的有好多问题不懂,麻烦你教教我
2016-04-28 16:53
一世沉浮
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-4-28
收藏
得分:0 
回复 15楼 alice_usnet
删了p->condition后,界面是这样的
图片附件: 游客没有浏览图片的权限,请 登录注册

我发现运行后不能返回主界面,就对主函数做了点修改,不然录入后就结束程序也没用啊,所以现在录入后就又会出现选项,不至于不能用。。
2016-04-28 18:13
快速回复:运用链表的程序,我估计是output()和foutput()错了,但是不知道错哪了 ...
数据加载中...
 
   



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

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