#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct consumer
{
char stu_name[30],stu_Place[20];//定义客户姓名,地点
char stu_time[20],stu_madetime[20],stu_memu[20]; //定义用餐时间,订单生成时间,菜单
int stu_num; //用餐人数
}order;
void reserve()//订餐
{
int i;
printf("请输入客户姓名:");
scanf("%s",&order.stu_name);
strcat(order.stu_name,".txt");//将后一个字符串加到前一个
FILE *fp1=fopen(order.stu_name,"w");//打开文档
if(fp1==NULL)//若文件打开失败
{
printf("文件打开失败\n");
exit(0);
}
FILE *fp2=fopen("d:\\总表.txt","a+");//打开文档
if(fp2==NULL)//若文件打开失败
{
printf("文件打开失败\n");
exit(0);
}
fprintf(fp1,"客户姓名:%s\n",order.stu_name);
fprintf(fp2,"客户姓名:%s\n",order.stu_name);
printf("请输入用餐人数:");
scanf("%d",&order.stu_num);
fprintf(fp1,"用餐人数:%d\n",order.stu_num);
fprintf(fp2,"用餐人数:%d\n",order.stu_num);
printf("请输入用餐时间:");
scanf("%s",&order.stu_time);
fprintf(fp1,"用餐时间:%s\n",order.stu_time);
fprintf(fp2,"用餐时间:%s\n",order.stu_time);
printf("请输入包间或餐桌号:");
scanf("%s",&order.stu_Place);
fprintf(fp1,"包间号\\餐桌号:%s\n",order.stu_Place);
fprintf(fp2,"包间号\\餐桌号:%s\n",order.stu_Place);
printf("请点菜:");
fprintf(fp1,"所点的菜:");
fprintf(fp2,"所点的菜:");
for(i=1;;i++)
{
scanf("%s",&order.stu_memu);
fprintf(fp1,"%s ",&order.stu_memu);
fprintf(fp2,"%s ",&order.stu_memu);
if(getchar()=='\n')
break;
}
printf("请输入订单生成时间:");
scanf("%s",&order.stu_madetime);
fprintf(fp1,"\n订单生成时间:%s",order.stu_madetime);
fprintf(fp2,"\n订单生成时间:%s",order.stu_madetime);
}
void find()//查询
{
char line1[150];
char line2[150];
char line3[150];
char line4[150];
char line5[150];
char line6[150];
printf("请输入客户名:");
scanf("%s",&order.stu_name);
strcat(order.stu_name,".txt");
FILE *fp;
if((fp=fopen(order.stu_name,"r"))==NULL)//打开文档;
{
printf("客户不存在");
exit(0);
}
fgets(line1,150,fp);
printf("%s\n",line1);
fgets(line2,150,fp);
c语言printf用法例子简单 printf("%s\n",line2);
fgets(line3,150,fp);
printf("%s\n",line3);
fgets(line4,150,fp);
printf("%s\n",line4);
fgets(line5,150,fp);
printf("%s\n",line5);
fgets(line6,150,fp);
printf("%s\n",line6);//读取文档和显示输出;
fclose(fp);
getchar();
}
void deletes()//删除
{
char line1[150];
char line2[150];
char line3[150];
char line4[150];
char line5[150];
char line6[150];
char reason[150];
char choice;
printf("请输入客户姓名:\n");
scanf("%s",&order.stu_name);
strcat(order.stu_name,".txt");
FILE *fp;
if((fp=fopen(order.stu_name,"r"))==NULL)//打开文档;
{
printf("无该用户");
exit(0);
}
fgets(line1,100,fp);
printf("%s",line1);
fgets(line2,100,fp);
printf("%s",line2);
fgets(line3,100,fp);
printf("%s",line3);
fgets(line4,100,fp);
printf("%s",line4);
fgets(line5,100,fp);
printf("%s",line5);
fgets(line6,100,fp);
printf("%s",line6);
fclose(fp);//读取文档和显示输出;
printf("是否确认删除y/n");
scanf("%s",&choice);
if(choice=='n')
{
exit(0);
}
else
{
printf("请输入您的和退订原因:");
scanf("%s",&reason);
FILE *fp2;
if((fp2=fopen("d:\\原因.txt","a+"))==NULL)
{
printf("fail");
exit(0);
}
fprintf(fp2,"%s",reason);
fclose(fp2);
strcat(order.stu_name,".txt");
FILE *fp;
if((fp=fopen(order.stu_name,"r"))==NULL)//打开文档;
{
printf("无该客户");
exit(0);
}
if(remove(order.stu_name)==0)//删除文档;
{
printf("已删除成功!");
exit(0);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论