主界面选择 2 订单详情 无法执行后面的函数 高手帮看看
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
void quit();
void List();//查询服务函数
void Details();//订单详情函数
void Order();//订单系统
void XiuGai();//修改订单
int k1 = 10, k2 = 10, k3 = 10;
int zx = 0;
struct bank
{
char name[20];//用户名
int number;//号码
char type[20];//类型
int order;//订单数
}kehu, t;
FILE *fp;
void main()//主函数
{
while (1)
{
system(“cls”);
int a;
printf(“\n\n\n\t\t\t\t\t\t欢迎进入预定系统\n”);
printf(“\n\n\t\t\t\t\t1、会议室信息”);
printf(“\n\n\t\t\t\t\t2、订单信息”);
printf(“\n\n\t\t\t\t\t3、退出系统”);
printf(“\n\n\t\t\t\t请选择服务:”);
scanf_s(“%d”, &a);
fflush(stdin);
if (a == 1)
List();
else if (a == 2)
Details();
else if (a == 3)
quit();
}
}
void List()
{
int b;
system(“cls”);
printf(“\n\n\n\n\t\t\t您正在使用的是查询功能”);
printf(“\n\n\t\t\t小型会议室还剩 %d 间”, k1);
printf(“\n\n\t\t\t中型会议室还剩 %d 间”, k2);
printf(“\n\n\t\t\t大型会议室还剩 %d 间\n”, k3);
printf(“\n\n\t\t\t请选择服务: 1、预订 2、返回\n”);
scanf(“%d”, &b);
if (b == 1)
{
Order();
}
else if (b == 2)
{
}
}
void Details()//订单详情
{
fopen_s(&fp, “atm.txt”, “rb+”);
if (fp == NULL)
{
printf(“\n\n\t\t\t打开失败\n”);
return;
}
printf(“\n\n\n\n\n\t\t您正在执行的是订单查询服务”);
int zhanghao, f = 0;
struct bank t;
printf(“\n\n\t\t\t请输入您的订单号:”);
scanf_s(“%d”, &zhanghao);
while(fread(&t, sizeof(t), 1, fp))
{
if (zhanghao == t.number)
{
f = 1;
break;
}
}
if (f==1)
{
XiuGai();
}
else
{
printf(“\n\n\t\t\t没有此订单号”);
}
fclose(fp);
}
void Order()
{
int c;
fopen_s(&fp, “atm.txt”, “ab+”);
if (fp == NULL)
{
printf(“文件打开失败”);
return;
}
printf(“\n\t\t\t请输入会议室类型:small middle or large\t”);
fflush(stdin);
gets_s(kehu.type);
printf(“\n\t\t\t请确认会议室类型:1、 small 2、 middle 3、large\t”);
scanf(“%d”, &c);
printf(“\n\t\t\t会议室类型为:%s\n”, kehu.type);
if (c == 1)
k1–;
else if (c == 2)
k2–;
else if (c == 3)
k3–;
rewind(fp);//将文件指针定位到文件开头
if (fread(&t, sizeof(t), 1, fp) == 1)
{
fseek(fp, -sizeof(kehu), 2);
fread(&t, sizeof(t), 1, fp);//读取最后一条记录
kehu.number = t.number + 1;
}
else
{
kehu.number = 20160001;
}
kehu.order = 0;
fseek(fp, 0, 2);
fwrite(&kehu, sizeof(struct bank), 1, fp);
fclose(fp);
printf(“\n\n\t\t\t预订成功\n”);
printf(“\n\n\t\t\t您的订单号为:%d\n”, kehu.number);
printf(“\n\n\n\t\t请牢记订单号,柜台前请出示订单号”);
printf(“\n\n\t\t\t按任意键继续…..”);
_getch();//不经过缓冲区的字符输入函数
}
void XiuGai()
{
int m;
printf(“请选择服务:1、取消订单 2、延时订单”);
scanf(“%d”, &m);
}
void quit()//退出函数
{
printf(“\n\n\n\n\n\n\t\t\t会议预订欢迎你下次再来”);
printf(“\n\n\n\n\n\t\t\t正在退出,请稍后\n”);
exit(0);//退出系统函数
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
void quit();
void List();//查询服务函数
void Details();//订单详情函数
void Order();//订单系统
void XiuGai();//修改订单
int k1 = 10, k2 = 10, k3 = 10;
int zx = 0;
struct bank
{
char name[20];//用户名
int number;//号码
char type[20];//类型
int order;//订单数
}kehu, t;
FILE *fp;
void main()//主函数
{
while (1)
{
system(“cls”);
int a;
printf(“\n\n\n\t\t\t\t\t\t欢迎进入预定系统\n”);
printf(“\n\n\t\t\t\t\t1、会议室信息”);
printf(“\n\n\t\t\t\t\t2、订单信息”);
printf(“\n\n\t\t\t\t\t3、退出系统”);
printf(“\n\n\t\t\t\t请选择服务:”);
scanf_s(“%d”, &a);
fflush(stdin);
if (a == 1)
List();
else if (a == 2)
Details();
else if (a == 3)
quit();
}
}
void List()
{
int b;
system(“cls”);
printf(“\n\n\n\n\t\t\t您正在使用的是查询功能”);
printf(“\n\n\t\t\t小型会议室还剩 %d 间”, k1);
printf(“\n\n\t\t\t中型会议室还剩 %d 间”, k2);
printf(“\n\n\t\t\t大型会议室还剩 %d 间\n”, k3);
printf(“\n\n\t\t\t请选择服务: 1、预订 2、返回\n”);
scanf(“%d”, &b);
if (b == 1)
{
Order();
}
else if (b == 2)
{
}
}
void Details()//订单详情
{
fopen_s(&fp, “atm.txt”, “rb+”);
if (fp == NULL)
{
printf(“\n\n\t\t\t打开失败\n”);
return;
}
printf(“\n\n\n\n\n\t\t您正在执行的是订单查询服务”);
int zhanghao, f = 0;
struct bank t;
printf(“\n\n\t\t\t请输入您的订单号:”);
scanf_s(“%d”, &zhanghao);
while(fread(&t, sizeof(t), 1, fp))
{
if (zhanghao == t.number)
{
f = 1;
break;
}
}
if (f==1)
{
XiuGai();
}
else
{
printf(“\n\n\t\t\t没有此订单号”);
}
fclose(fp);
}
void Order()
{
int c;
fopen_s(&fp, “atm.txt”, “ab+”);
if (fp == NULL)
{
printf(“文件打开失败”);
return;
}
printf(“\n\t\t\t请输入会议室类型:small middle or large\t”);
fflush(stdin);
gets_s(kehu.type);
printf(“\n\t\t\t请确认会议室类型:1、 small 2、 middle 3、large\t”);
scanf(“%d”, &c);
printf(“\n\t\t\t会议室类型为:%s\n”, kehu.type);
if (c == 1)
k1–;
else if (c == 2)
k2–;
else if (c == 3)
k3–;
rewind(fp);//将文件指针定位到文件开头
if (fread(&t, sizeof(t), 1, fp) == 1)
{
fseek(fp, -sizeof(kehu), 2);
fread(&t, sizeof(t), 1, fp);//读取最后一条记录
kehu.number = t.number + 1;
}
else
{
kehu.number = 20160001;
}
kehu.order = 0;
fseek(fp, 0, 2);
fwrite(&kehu, sizeof(struct bank), 1, fp);
fclose(fp);
printf(“\n\n\t\t\t预订成功\n”);
printf(“\n\n\t\t\t您的订单号为:%d\n”, kehu.number);
printf(“\n\n\n\t\t请牢记订单号,柜台前请出示订单号”);
printf(“\n\n\t\t\t按任意键继续…..”);
_getch();//不经过缓冲区的字符输入函数
}
void XiuGai()
{
int m;
printf(“请选择服务:1、取消订单 2、延时订单”);
scanf(“%d”, &m);
}
void quit()//退出函数
{
printf(“\n\n\n\n\n\n\t\t\t会议预订欢迎你下次再来”);
printf(“\n\n\n\n\n\t\t\t正在退出,请稍后\n”);
exit(0);//退出系统函数
}
解决方案:20分
本人单步跟踪程序运行,是不是文件没有打开成功,然后函数就返回了
解决方案:20分
截个运行效果图来看看