| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2901 人关注过本帖
标题:求指点~一个编译没有错但运行总崩溃的程序,谢谢
取消只看楼主 加入收藏
是心愿
Rank: 1
等 级:新手上路
帖 子:75
专家分:0
注 册:2016-6-22
结帖率:62.5%
收藏
已结贴  问题点数:20 回复次数:2 
求指点~一个编译没有错但运行总崩溃的程序,谢谢
目的是想要删除文件中的一个航班信息,然后再把删除的航班信息读出,这个程序编译没有错,但是总是崩溃,求指点




#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define whole 81

void deleteFlight();
struct flyline
    {
        char fnum[whole];
        char fcompany[whole];
        char fstart[whole];
        char fend[whole];
        char fstime[whole];
        char ftime[whole];
        char ftype[whole];
        char frate[whole];
        char ftprice[whole];
        char ftrest[whole];
        char fyprice[whole];
        char fyrest[whole];
        char fp1[whole];
        char fp2[whole];
    };
   
   
    struct flyline line[31]={{"航班号","所属公司","出发地","降落地","起飞时间","预计飞行时间","机型","准点率","头等舱票价","头等舱剩余座位","经济舱票价","经济舱剩余座位","驾驶员","副驾驶\n"},
                             {"SC8835","山东航空公司","北京","珠海","6:35","210min","738","93%","¥5080","6","¥2030","33","Zhao Yi","Zhao Er\n"},
                             {"SC1195","山东航空公司","北京","银川","7:05","135min","738","98%","¥3540","8","¥1180","25","zhao san","zhao si\n"},  
                              {"SC4785","山东航空公司","北京","盐城","8:00","115min","738","80%","¥1960","2","¥980","12","zhao wu","zhao liu\n"},
                              {"SC4852","山东航空公司","北京","青岛","9:50","90min","747","90%","¥1640","5","¥820","34" ,"zhao qi","zhao ba\n"},
                              {"SC4882","山东航空公司","北京","珠海","10:45","240min","635","96%","¥5240","2","¥2320","11","zhao jiu","zhao shi\n"},
                             {"SC4854","山东航空公司","北京","烟台","13:45","100min","482","92%","¥4200","0","¥2100","9","qian yi","qian er\n"},
                             {"SC4678","山东航空公司","北京","厦门","15:20","100min","482","95%","¥2440","5","¥1220","17","qian san","qian si\n"},
                             {"SC4856","山东航空公司","北京","重庆","20:05","185min","738","85%","¥3860","1","¥1980","3","qian wu","qian liu\n"},
                             {"3U8548","四川航空公司","成都","北京","6:25","190min","321","78%","¥4730","3","¥1690","28","qian qi","qian ba\n"},
                             {"3U8303","四川航空公司","哈尔滨","北京","6:50","120min","319","81%","¥3050","7","¥1520","13","qian jiu","qian shi\n"},
                             {"3U8896","四川航空公司","西昌","北京","7:25","305min","320","91%","¥4820","3","¥2410","3","sun yi","sun er\n"},
                             {"3U8838","四川航空公司","昆明","北京","8:10","295min","320","87%","¥3460","0","¥1730","23","sun san","sun si\n"},
                             {"3U8832","四川航空公司","万县","北京","17:30","140min","319","86%","¥2850","4","¥1920","5","sun wu","sun liu\n"},
                             {"3U8894","四川航空公司","成都","北京","19:30","190min","320","90%","¥4730","1","¥1690","0","sun qi","sun ba\n"},
                             {"3U8830","四川航空公司","重庆","北京","10:45","195min","321","87%","¥3660","4","¥1820","31","sun jiu","sun shi\n"},
                             {"3U8892","四川航空公司","三亚","北京","7:55","245min","321","93%","¥3870","2","¥1980","19","li san","li si\n"},
                              
                            };
   


FILE*fline;
int main()
    {
           char fnum3[8];
        int i;
        int n3_3=0;
        if((fline=fopen("finformation.txt","rb"))==NULL)/*打开文件*/
       {
            printf("文件读取失败……");
            exit(0);
       }
        
        printf("请输入您要删除的航班号:\n");
        scanf("%s",&fnum3);/*管理员输入想删除的航班号*/
        
        while(!feof(fline))/*统计全部航班信息个数*/
         {
             fread(&line[n3_3],sizeof(struct flyline),1,fline);
             n3_3++;
         }
         
         for (i = 0; i<n3_3; i++) /*依次对比检查*/
         {
            if (strcmp(line[i].fnum, fnum3) == 0)
            break;
         }
         
         for (; i<n3_3; i++) /*删除航班*/
         {
             line[i]=line[i+1];
             n3_3=n3_3-1;
             printf("成功删除!\n");
          }
         
         if(i==n3_3);
         printf("没有该航班号!\n");
         
         for (i = 0; i<n3_3; i++) /*写入文件*/
         fwrite(&line[i],sizeof(struct flyline) , 1, fline);
         
         fclose(fline);
         
         int d1;
        if((fline=fopen("finformation.txt","rb"))==NULL)
        {
           printf("文件读取失败……");
        }
        
         
   
          for(d1=0;d1<n3_3;d1++)
        {
            fread(&line[d1],sizeof(struct flyline),1,fline);
            printf("  %-8s%-14s%-8s%-8s%-10s%-14s%-7s%-8s%-12s%-16s%-12s%-16s%-10s%-6s",line[d1].fnum,line[d1].fcompany,line[d1].fstart,line[d1].fend,line[d1].fstime,line[d1].ftime,line[d1].ftype,line[d1].frate,line[d1].ftprice,line[d1].ftrest,line[d1].fyprice,line[d1].fyrest,line[d1].fp1,line[d1].fp2);
        }
      
           fclose(fline);
    }
        
搜索更多相关主题的帖子: include whole 信息 
2016-09-04 20:52
是心愿
Rank: 1
等 级:新手上路
帖 子:75
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 2楼 ehszt
finformation.rar (1.44 KB)
2016-09-04 21:37
是心愿
Rank: 1
等 级:新手上路
帖 子:75
专家分:0
注 册:2016-6-22
收藏
得分:0 
回复 5楼 ehszt
谢谢您,辛苦了!都是我基础太差。。要编的程序也有点复杂。。
我会好好学习C语言的
2016-09-04 23:33
快速回复:求指点~一个编译没有错但运行总崩溃的程序,谢谢
数据加载中...
 
   



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

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