标题:数据结构输入问题
只看楼主
Ially1008
Rank: 2
等 级:论坛游民
帖 子:5
专家分:30
注 册:2012-3-29
结帖率:50%
已结贴  问题点数:20 回复次数:1 
数据结构输入问题
我初学数据结构,在做一个大作业,是关于交通咨询的,这是一小部分。在主函数中的输入有问题,运行会自动停止,求指教。
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>

typedef struct
{
    char flightnum;
    char flightbegin;
    char flightend;
    double time;
    double fee;
}flight;
typedef struct
{
    char trainnum;
    char trainbegin;
    char trainend;
    double time;
    double fee;
}train;
typedef struct {
    char begin;
    char end;
    flight finformation;
    train tinformation;
    double distance;
    int flag;
}information;
typedef struct node
{
    information trip;
    struct node *next;
}node,*LNode;
void case1();
int main()
{
    int i;
    printf("\n\n\n\n");
    printf("                     **********************************************\n");
    printf("                     *                                            *\n");
    printf("                     *            全国交通咨询模拟                *\n");
    printf("                     *                                            *\n");
    printf("                     **********************************************\n");
    printf("按任意键继续\n");
    getchar();
    system("cls");
    printf("\n\n\n\n");
    printf("                                      选择要实现的功能\n");
    printf("                     *********************************************\n");
    printf("                     **                1.管理员操作             **\n");
    printf("                     **                2.用户咨询               **\n");
    printf("                     **                3.退出系统               **\n");
    printf("                     *********************************************\n");
    printf("                     *选择功能?\n*");
    scanf("%d",&i);
    system("cls");
    if(i==1)
        case1();
}
void case1()
{
    LNode head,p1;
    head=(LNode)malloc(sizeof(node));p1=head;
    int i;char c;
    printf("\n\n\n\n");
    printf("                                    选择编辑方式\n");
    printf("                     *********************************************\n");
    printf("                     **                1.键盘                   **\n");
    printf("                     **                2.文件                   **\n");
    printf("                     *********************************************\n");
    printf("                     *选择功能?\n*");
    scanf("%d",&i);
    if(i==1)
    {
        //将信息读入链表中(起点,终点,来往的飞机(航班号,起飞时间,降落时间,飞行时间,费用),来往的火车(列车号,出发时间,到站时间,行驶时间,费用),城市距离)
        while(1)
        {
            p1=(LNode)malloc(sizeof(node));
            p1=p1->next;
            scanf("%s",&p1->trip.begin);scanf("\n");scanf("%s",&p1->trip.end);
            scanf("%s",&p1->trip.finformation.flightnum);
            scanf("%s",&p1->trip.finformation.flightbegin);
            scanf("%s",&p1->trip.finformation.flightend);
            scanf("%lf %lf",&p1->trip.finformation.time,&p1->trip.finformation.fee);
            scanf("%s",&p1->trip.tinformation.trainnum);
            scanf("%s",&p1->trip.tinformation.trainbegin);
            scanf("%s",&p1->trip.tinformation.trainend);
            scanf("%lf %lf",&p1->trip.tinformation.time,&p1->trip.tinformation.fee);
            scanf("%lf",&p1->trip.distance);
               }
    }
}
搜索更多相关主题的帖子: 数据 double include flight 
2012-05-01 14:05
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
得分:20 
p1=p1->next;
 
指向的地址有问题
2012-05-04 12:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-366793-1-1.html




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

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