⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_file_read.c

📁 这是一个飞机的C程序编写的代码,你能从中知道如何去订瓢
💻 C
字号:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define SIZE 3
#define MAX 13
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -2
#define OPSETSIZE 7
#define STACK_INIF_SIZE 50
#define STACKINCREMENT 10
#define PR printf
//FILE *fp_airline,*fp_customer,*fp;

typedef int status;
typedef struct airline{
	char line_num[8];//航班号
	char plane_num[8];//飞机号
	char end_place[20];//目的的
	int total;//座位总数
	int left;//剩余座位
	struct airline *next;//下一个结点
}airline;

typedef struct customer{
	char name[9];//顾客名
	char line_num[8];//航班号
	int seat_num;//座位号
	struct customer *next;//下一个结点
}customer;

status init_airline(airline *l){//初始化链表
	l=(airline*)malloc(sizeof(airline));
	if(l==NULL){
		exit(OVERFLOW);
		}
	l->next=NULL;
	return OK;
}

status init_cus(customer *l){//初始化链表
	l=(customer*)malloc(sizeof(customer));
	if(l==NULL){
		exit(OVERFLOW);
		}
	l->next=NULL;
	return OK;
}

status insert_airline(airline **p,char *line_num,char *plane_num,char *end_place,int total,int left){//airline链表插入操作
	airline *q;
	q=(airline*)malloc(sizeof(airline));
	strcpy(q->line_num , line_num);
	strcpy(q->plane_num , plane_num);
	strcpy(q->end_place , end_place);
	q->total  =total;
	q->left =left;
	q->next=NULL;
	(*p)->next=q;
	(*p)=(*p)->next;
 //   printf("insert %d	,%dis succssed!\n",e,bl);
	return OK;
	}

status insert_cus(customer **p,char *name,char *line_num,int seat){//customer链表插入操作
	customer *q;
	q=(customer*)malloc(sizeof(customer));
	strcpy(q->name , name);
	strcpy(q->line_num , line_num);
	q->seat_num =seat;
	q->next=NULL;
	(*p)->next=q;
	(*p)=(*p)->next;
 //   printf("insert %d	,%dis succssed!\n",e,bl);
	return OK;
	}

customer *delete_cus(customer *h,char *name)
{
	customer *p,*pr,*q,*qr;
	qr=pr=h;
	p=pr->next ;
	q=qr->next ;
	while(p!=NULL)
	{
		if(strcmp(name,p->name )==0)
		{
			qr->next =q->next ;
			PR("delet %s\n",q->name );
			return h;
		}
		qr=qr->next ;
		q=qr->next ;
	}
	PR("没有这用户,无法完成删除任务!\n");
	return 0;
}

airline *modefy_airline(airline *l,char *line_num)
{
	airline *q;
	q=l->next ;
	for(;q->next !=NULL;q=q->next )
	{
		if(strcmp(line_num,q->line_num )==0)
		{
			q->left ++;
			PR("modefy %s\n",q->line_num );
			return l;
		}
	}
	PR("没有这个航线,无法完成修改任务!\n");
	return 0;
}

status save_airline(airline *l)
{
	FILE *fp_airline;
	airline *p=l->next ;
	char filename[50]="c:\\airline.dat";
	if((fp_airline=fopen("filename","wb"))==NULL)
	{
		printf("can not open file to write:%s\n",filename);
		return ERROR;
	}
	for (;p->next !=NULL;p=p->next ){
		if(fwrite(p,sizeof(airline),1,fp_airline)!=1)
		{
			PR("airline_dat write error\n");
			fclose(fp_airline);
			return ERROR;
		}
	}
	fclose(fp_airline);
	return OK;
}

status save_customer(customer *l)
{
	FILE *fp_customer;
	customer *p=l->next ;
	char filename[50]="c:\\customer.dat";
	if((fp_customer=fopen("filename","wb"))==NULL)
	{
		printf("can not open file to write:%s\n",filename);
		return ERROR;
	}
	for (;p->next !=NULL;p=p->next ){
		if(fwrite(p,sizeof(customer),1,fp_customer)!=1)
		{
			PR("customer_dat write error\n");
			fclose(fp_customer);
			return ERROR;
		}
	}
	fclose(fp_customer);
	return OK;
}	

status load_airline(airline *l)
{
	FILE *fp_airline;
	airline *p=l->next ;
	char filename[50]="c:\\airline.dat";
	if((fp_airline=fopen("filename","rb"))==NULL)
	{
		printf("can not open file to load:%s\n",filename);
		return ERROR;
	}
	for (;p->next !=NULL;p=p->next ){
		if(fread(p,sizeof(airline),1,fp_airline)!=1)
		{
			PR("airline_dat load error\n");
			fclose(fp_airline);
			return ERROR;
		}
	}
	fclose(fp_airline);
	return OK;
}

status load_customer(customer *l)
{
	FILE *fp_customer;
	customer *p=l->next ;
	char filename[50]="c:\\customer.dat";
	if((fp_customer=fopen("filename","rb"))==NULL)
	{
		printf("can not open file to load:%s\n",filename);
		return ERROR;
	}
	for (;p->next !=NULL;p=p->next ){
		if(fread(p,sizeof(customer),1,fp_customer)!=1)
		{
			PR("customer_dat load error\n");
			fclose(fp_customer);
			return ERROR;
		}
	}
	fclose(fp_customer);
	return OK;
}


	
void main()
{

	PR("main\n");
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -