按照我的设想,应该重回loop位置后再有scanf请求输入的,然后到switch继续循环,但是运行结果确实直接跳过去了,为什么?
#include<stdio.h>
#include<string.h>
typedef struct {
int sit_num;
int order;
char nachname[20];
char vorname[20];
}plane;
void plan_a(plane *p);
void plan_b(plane *p);
void plan_c(plane *p);
void plan_d(plane *p);
void plan_e(plane *p);
int main() {
plane A[11]={};//运行前自行初始化录入数据
loop: printf("To choose a functions, enter its letter label:\n");
printf("a) Show number of empty seats\n");
printf("b) Show list of empty seats\n");
printf("c) Show alphabetical list of seats\n");
printf("d) Assign a customer to a seat assignment\n");
printf("e) Delete a seat assignment\n");
printf("f) Quit\n");
char n, m;
scanf("%c", &n);
if (n == 'f')
goto q2;
switch (n)
{
case 'a':plan_a(A); goto loop; break;
case 'b':plan_b(A); goto loop; break;
case 'c':plan_c(A); goto loop; break;
case 'd':plan_d(A); goto loop; break;
case 'e':plan_e(A); goto loop; break;
case 'f':break;
default:
break;
}
q2:printf("程序结束");
return 0;
}
void plan_a(plane *p) {
int LL = 0;
printf("如要中止,请按1后回车;如需继续,请按0后回车");
scanf("%d", &LL);
if (LL == 1)
goto qq;
int sum_order = 0;
int i=0;
for (i = 0; i < 12; i++) {
if ((p+i)->order == 0)
sum_order = sum_order + 1;
}
printf("%d\n", sum_order);
qq:if (LL == 1)
printf("返回菜单");
}
void plan_b(plane *p) {
int LL = 0;
printf("如要中止,请按1后回车;如需继续,请按0后回车");
scanf("%d", &LL);
int i=0;
if (LL == 1){
goto qq;}
for (i = 0; i < 12; i++)
{
if ((p+i)->order == 0)
printf("%d\n", (p+i)->sit_num);
}
qq:if (LL == 1)
printf("返回菜单");
}
void plan_c(plane *p) {
int LL = 0;
printf("如要中止,请按1后回车;如需继续,请按0后回车");
scanf("%d", &LL);
if (LL == 1)
goto qq;
int i=0;
for (i = 0; i < 12; i++)
{
printf("%d\n", (p + i)->sit_num);
}
qq:if (LL == 1)
printf("返回菜单");
}
void plan_d(plane *p) {
int LL = 0;
printf("如要中止,请按1后回车;如需继续,请按0后回车");
scanf("%d", &LL);
if (LL == 1)
goto qq;
int L2 = 0;
printf("请输入预订座位号\n");
scanf("%d", &L2);
(p + L2)->order = 1;
printf("请输入预订人的名\n");
scanf("%s", &(p + L2)->nachname);
printf("请输入预定人的姓\n");
scanf("%s", &(p + L2)->vorname);
qq:if (LL == 1)
printf("返回菜单");
}
void plan_e(plane *p) {
int LL = 0;
printf("如要中止,请按1后回车;如需继续,请按0后回车");
scanf("%d", &LL);
if (LL == 1)
goto qq;
int L3 = 0;
printf("请输入删除座位编号");
scanf("%d", &L3);
char zero[20] = { 0 };
strcpy((p + L3)->nachname, zero);
strcpy((p + L3)->vorname, zero);
(p + L3)->order = 0;
qq:if (LL == 1)
printf("返回菜单");
}