为什么只能储存一个信息
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#define SIZE 10
struct hotel
{
int jiage;/*价格*/
int id;/*房间号码*/
int kk;/*用来检测是否有人居住*/
}room[]={{100,101,0},{100,102,0},{100,103,0},{100,104,0},{100,105,0},{100,201,0},{100,202,0},{100,203,0},{100,204,0},{100,205,0}};
struct people
{
char name[10];
char ID[20];
char sex[2];
int time;/*入住的时间*/
}ke[SIZE];
int n=0;
void main()
{
void Insert();
void Search();
void Show();
void save();
void load();
void jie();
int i;
load();
do{
printf("\t***********************************\n");
printf("\t*******欢迎登入酒店管理系统********\n");
printf("\t***********************************\n");
printf("\t 0.登记入住(Insert) \n");
printf("\t 1.查询房间的入住境况(Search) \n");
printf("\t 2.查询费用(Show) \n");
printf("\t 3.结账(jie) \n");
printf("\t 4.退出程序 \n");
scanf("%d",&i);
switch(i)
{
case 0:Insert();
break;
case 1:Search();
break;
case 2:Show();
break;
case 3:jie();
break;
case 4:
break;
default:printf("错误选择:请重新选");break;
}
}while(i>=0&&i<=3);
}
void load()
{
FILE *fp;
if((fp=fopen("ke.dat","rb"))==NULL)
{
printf("cannot open infile\n");
return;
}
fread(&n,sizeof(struct people),1,fp);
fread(ke,sizeof(struct people),n,fp);
fclose(fp);
}
void save()
{
FILE *fp;
if((fp=fopen("ke.dat","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
fwrite(&n,sizeof(struct people),1,fp);
fwrite(ke,sizeof(struct people),n,fp);
fclose(fp);
}
void Insert()
{
void load();
int a,b=0;
for(a=0;a<SIZE;a++)
{
if(room[a].kk==0)
printf("可选房间:%d\n",room[a].id);
else
{
printf("房间已住满:\n");
return;
}
}
printf("请选择你的房间\n");
scanf("%d",&room[0].kk);
printf("请输入你的名字:\n");
scanf("%s",ke[0].name);
printf("请输入你的身份证号码:");
scanf("%s",ke[0].ID);
while((strlen(ke[0].ID)!=18)&&(strlen(ke[0].ID)!=15))
{
printf("%d",strlen(ke[0].ID));
printf("输入错误:请重新输入");
printf("请输入你的身份证号码:");
scanf("%s",ke[0].ID);
}
printf("请输入你的性别:\n");
scanf("%s",ke[0].sex);
printf("请输入入住天数:\n");
scanf("%d",&ke[0].time);
room[0].kk=1;
n++;
save();
}
void Search()
{
int l;
void look2();/*按名字查询*/
void look1();/*按房间号码查询*/
printf("请输入你要查询的方式:0按房间号码查询,1按名字查询\n");
scanf("%d",&l);
switch(l)
{
case 0: look1();break;
case 1: look2();break;
default:printf("输入错误:\n");break;
}
}
void look1()
{
int n,id;
printf("请输入你的房间号码\n");
scanf("%d",&id);
for(n=0;n<SIZE;n++)
{
if(room[n].id==id)
{
printf("名字:%s\n",ke[n].name);
printf("身份证号码:%s\n",ke[n]. ID);
printf("性别:%s\n",ke[n].sex);
break;
}
}
}
void look2()
{
int n;
char name[10];
printf("请输入你的名字:\n");
scanf("%s",name);
for(n=0;n<SIZE;n++)
{
if(strcmp(name,ke[n].name)==0);
{
printf("你的身份证号码是:%s\n",ke[n].ID);
printf("你的房间号码是:%d\n",room[n].id);
printf("性别:%s",ke[n].sex);
break;
}
}
}
void Show()
{
int i=0;
printf("请选择要查询人的房间号码:\n");
scanf("%d",&room[0].kk);
printf("入住的天数:%d\n",ke[0].time);
printf("所用费用:%d\n",ke[0].time*room[0].jiage);
}
void jie()
{
int j=0,k;
printf("请输入你的房间号码\n");
scanf("%d",&j);
printf("是否退房,是按1,不是按2\n");
scanf("%d",&k);
switch(k)
{
case 1:room[j].kk=0;break;
case 2:break;
}
}