#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
#define max 5
int num=5;
struct gues {
char name[20];
char telephone[20];
int sum;
char time[10];
} guestlist[max]= {"zhanglin","1234567891",5,"11.30",
"liyong","1234567892",3,"12.30",
"liuying","1234567893",6,"12.00",
"zhaopeng","1234567894",4,"12.20",
"moqing","1234567895",7,"11.50"
};
void insert(struct gues *p);
void search(struct gues *p);
void update(struct gues *p);
void Delete(struct gues *p);
void show(struct gues *p);
int main(int argc, char* argv[])
{
for(int i=0; i<999; i++)
{
int choose=0;
printf("\n1插入\n2查询\n3修改\n4删除\n5显示\n");
scanf_s("%1d%*c",&choose);
switch(choose)
{
case 1:
insert(guestlist);
break;
case 2:
search(guestlist);
break;
case 3:
update(guestlist);
break;
case 4:
Delete(guestlist);break;
case 5:
show(guestlist);break;
}
}
return 0;
}
void insert(struct gues *p)
{ int i;
if(num==5)
printf("无多余餐桌");
//printf("分别输入名字,电话,人数,时间(用空格分开)");
else
for(i=0; p[i].sum=0; i++)
{printf("%d",&p[i].sum);
printf("输入名字");
scanf_s("%s",p[i].name);
printf("输入电话");
scanf_s("%s",p[i].telephone);
printf("输入人数");
scanf_s("%d",&p[i].sum);
printf("输入时间");
scanf_s("%s",&p[i].time);
}
}
void search(struct gues *p) {
char tele[20];
printf("输入电话号码");
scanf_s("%19s%*c", tele);
//gets(tele);
int i;
int flag=0;
for(i=0; i<max; i++) {
if(strcmp(p[i].telephone,tele)==0) {
flag=1;
printf("%s\n%s\n%d\n%s\n",guestlist[i].name,guestlist[i].telephone,guestlist[i].sum,guestlist[i].time);
break;
}
}
if(flag == 0)
printf("没有查询到此人信息");
else
printf("客人资料为上述");
}
void update(struct gues *p) {
printf("输入电话号码");
char phone[20];
gets_s(phone);
int i;
for(i=0; i<max; i++) {
if(strcmp(p[i].telephone,phone)==0) {
printf("请输入重新修改后的所有数据(用空格分开)");
scanf_s("%19s %19s %d %9s%*c",p[i].name,p[i].telephone,&p[i].sum,p[i].time);
}
}
}
void Delete(struct gues *p)
{ printf("输入电话号码");
char phone[20];
gets_s(phone);
int i;
num=num-1;
for(i=0;i<max;i++)
if(strcmp(p[i].telephone,phone)==0)
{ memset(p[i].name,'\0',sizeof(p[i].name));
//strcpy_s(p[i].name,"o");
strcpy_s(p[i].telephone,"0");
p[i].sum=0;
strcpy_s(p[i].time,"0");
}
}
void show(struct gues *p)
{int i;
for(i=0;i<max;i++)
{printf("%s\n,%s\n,%d\n,%s\n",p[i].name,p[i].telephone,p[i].sum,p[i].time);
}
}
![图片说明](https://img-ask.csdn.net/upload/201902/25/1551096968_910430.png)如图 else部分不执行tiao'guo