Lawrence_008
Lawrence_008
采纳率0%
2017-06-05 03:35 阅读 2.7k

C语言修改文件中的数据

#include"string.h”
#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define MAXSIZE 3
typedef struct airline
{
char str_name[10];/*起点站名 /
char ter_name[10];/
终点站名 /
char air_num[10];/
航班号*/
char plane_num[10];/*飞机号*/
char day[7];/*飞行周日(星期几)*/
int tkt_amt;/*乘员定额*/
int tkt_sur;/*余票量*/
int money;
}lineinfo;

struct airline start;
struct airline *find()
/
根据系统提出的航班号查询并以指针形式返回*/
{
struct airline *info;
char number[10];
int i = 0;
info = start;
printf("请输入航班号:");
scanf("%s", number);
while (i if (!strcmp(number, info->air_num))
return info;
info++;
i++;
}
printf("对不起,该航线末找到!\n");
return NULL;
}

struct airline *fix_start(struct airline *p)
{
// 求大神在这里用文件修终点站名
return p;
}
void display(struct airline *p)

{
printf("%8s\t%8s\t%3s\t%s\t%4s\t\t%3d\t%10d\t%10d\n", p->str_name, p->ter_name, p->air_num, p->plane_num, p->day, p->tkt_amt, p->tkt_sur, p->money);
}

void main() /* 主函数 */
{
int i = 0;
struct airline * p;
FILE *fp = NULL;
struct airline air[MAXSIZE];
char msg[1024] = { 0 };
fp = fopen("初始航线.txt", "r");
if (fp == NULL)
{
printf("读取失败");
}
else
{
while (fgets(msg, 1024, fp) != NULL)
{
sscanf_s(msg, "%s %s %s %s %s %d %d %d", &air[i].str_name, 20, &air[i].ter_name, 20, &air[i].air_num, 20, &air[i].plane_num, 20, &air[i].day, 20, &air[i].tkt_amt, &air[i].tkt_sur, &air[i].money);
i++;
}
}
if (i == MAXSIZE)
printf("读取成功\n");
system("pause");
start = &air[0];
p = find();
fix_start(p);
display(p);

}
这个是文件内容
shanghai beijine 1 B8571 SUN 3 3 100
beijing shanghai 2 S1002 MON 2 2 200
tianjing london 3 L1003 FRI 1 1 300

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • shen_wei shen_wei 2017-06-05 07:05

    使用这样发帖。。。不然代码不全。。。

     struct airline *fix_start(struct airline *p)
    {
        //获取输入的航班终点名并写入到文件中
    
        return p;
    }
    
    点赞 评论 复制链接分享

相关推荐