请教文件读写,谢谢
谢谢各位了,帮忙看看为什么读文件读不出来typedef struct inforair{
int air; //航班号
int prise; //票价
}inforair; //定义航班表信息节点
typedef struct infortrain{
//出发站
//终点站
int prise; //票价;
int train; //列车次
}infortrain ; //定义列车时刻表信息节点
typedef struct node1{
char *start0; //出发站
char *end0; //终点站
inforair *air; //航班信息
infortrain *train; //列车时刻表信息
node1 * next; //指向下一个节点的指针
}node1; //定义边的信息
typedef struct node2{
char *city; //城市名称
node2* downext; //指向下一个头结点
node1 * rnext; //指向边节点
}node2;
class wenjian
{
public:
void print();
void InsertArc();
wenjian();
virtual ~wenjian();
};
void wenjian::InsertArc()
{
node1 city;FILE* f,*fp;int a;char ch;
if((f=fopen("列车时刻表","a+"))==NULL)
{
printf("文件打开失败\n");
return;
}
city.start0=(char*)malloc(sizeof(char));
city.end0=(char*)malloc(sizeof(char));
city.next=NULL;
city.train=NULL;
city.air=NULL;
while((city.train=(infortrain*)malloc(sizeof(infortrain)))==NULL)
city.train=(infortrain*)malloc(sizeof(infortrain));
printf("输入起始站: ");
scanf("%s",city.start0);
printf("输入终止站: ");
scanf("%s",city.end0);
printf("输入列车次:");
scanf("%d",&city.train->train);
printf("输入票价:");
scanf("%d",&city.train->prise);
printf(""); //输入起始时间
fwrite(&city,sizeof(node1),1,f);
fclose(f);
}
void wenjian::print()
{
FILE *f,*fp;node1 city;
if((f=fopen("列车时刻表","r+"))==NULL)
{
printf("文件打开失败\n");
return;
}
printf("列车时刻表\n");
while(fread(&city,sizeof(node1),1,f))
{
if(city.train!=NULL)
printf("列车次:%d 起始站: 终止站: 出站时刻: 进站时刻:票价:",city.train->train);
}
fclose(f);
}
#include "stdafx.h"
#include"wenjian.h"
int main(int argc, char* argv[])
{
wenjian l;
//l.InsertArc();
l.print();
printf("Hello World!\n");
return 0;
}