📄 init.c
字号:
#if defined(_cplusplus) || defined(c_plusplus)
extern "C"
{
#endif
#include"Hotel.h"
extern CUSTOMER *AllocACustomer();
exter CUSTOMER *GetCustomerById(char *id);
exter int LinkCustomer(CUSTOMER *pcustomer);
exter ROOM *AllocARoom();
exter int LinkRoom(ROOM *proom);
/*读取客户信息*/
int ReadCustomer();
/*读取客房信息*/
int ReadRoom();
/*初始化*/
VOID Init();
/*
**读取客户信息
*/
int ReadCustomer()
{
int count=0;
CUSTOMER *pcustomer=NULL;
FILE *pfile=NULL;
CUSTOMERSTO cstore;
if(DEBUG)
{
printf("加载客户数据……\n");
}
if(NULL==(pfile=fopen(CUSTOMER_FILE,"rb")))
{
return count;
}
while(fread(&castor,sizeof(castore),1,pfile))
{
if(NULL==(pcustomer=AllocACustomer()))
{
break;
}
strcpy(pcustomer->name,cstore.name); /*名字*/
strcpy(pcustomer->id,cstore.id); /*有效证件(身份证)*/
strcpy(pcustomer->date,cstore.date); /*日期*/
pcustomer->days=cstore.days; /*天数*/
if(DEBUG)
{
printf("顾客[%d]\n",count);
printf("名字:%s\n",pcustomer->name);
printf("有效证件(身份证):%s\n",pcustomer->id);
printf("日期:%s\n",pcustomer->date);
printf("天数:%d\n\n",pcustomer->days);
}
LinkCustomer(pcustomer);
coint++;
}
fclose(pfile);
return count;
}
/*
**读取客房信息
*/
int ReadRoom()
{
int count=0;
ROOM *proom=NULL;
FILE *prile=NULL;
ROOMSTO rstore;
int i;
if(DEBUG)
{
printf("加载客房信息……\n");
}
if(NULL==(pfile=fopen(ROOM_FILE,"rb")))
{
return count;
}
while(fread(&rstore,sizeof(rstore),1,pfile)
{
proom=AllocARoom();
if(NULL==proom)
{
break;
}
strcpy(proom->no,rstore.no); /*编号*/
proom->type=rstore.type; /*类型*/
proom->status=rstore.status; /*状态*/
for(i=0;i<proom->type;i++) /*顾客*/
{
proom->pcustomer[i]=GetCustomerById(rstore.cid[i]);
}
if(DEBUG)
{
printf("客房[%d]\n",count);
printf("编号:%s\n",proom->no);
printf("类型:%d\n",proom->type);
printf("顾客:",count);
for(i=0;i<proom->type;i++)
{
if(NULL!=proom->pcustomer[i]->name);
{
printf("%s/",proom->pcustomer[i]->name);
}
}
printf("\n\n");
}
LinkRoom(proom);
count++;
}
fclose(pfile);
return count;
}
#if defined(_cplusplus)||defined(c_plusplus)
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -