多多的问题。。

nl_eve 2009-05-26 08:52:35
1.为什么GOTO的标签提示错误。
2.删掉的记录不就没了么,那退票记录又回去了怎么弄。
3.主函数调用函数时为什么提示语法表达错误。
这个程序是火车票订票系统,要实现订票,退票,查询,管理员管理,有得部分还没写,大家给点意见。谢谢啦。


#include"stdio.h"
#define L sizeof(struct tikets)
#define T1 "%s%s%d%d%s"
#define N sizeof(struct you1)

void book();
void inquire();
void you();

struct tikets
{
char name[10];
char name2[10];
int num1;
int num2;
char num3[10];
struct tikets *next;
}*save1;

struct you1
{
char user[10];
char card[20];
struct tikets *u;
}you2;



void main()
{
int *t;
int i;
first:
printf("welcome to the system!\n");
printf("1.intput the data.\n");
printf("2.book the tikets.\n");
printf("3.inquire the tikets.\n");
printf("4.cancel the tikets.\n");
printf("5input your own data.\n");
scanf("%d",&i);
read(struct tikets *save);
switch(i)
{
case '1':
book(struct tikets *save);
break;
case '2':
inquire(struct tikets *save);
break;
/*case '3':
cancel(struct tikets *save);
break;*/
case '4':
you(struct tikets *save);
break;
default:
printf("you enter an error number\n");
}
}

void read(struct tikets *save)
{
FILE *fp;
int j;
fp=open("tikets","r");
for(j=0;j<2;j++)
{
fread(save,L,1,fp);
printf(T1,save);
}
fclose(fp);
}

void book(struct tikets *save)
{
struct tikets *b1,*pre,*b2;
printf("please enter the carnum;\n");
gets(carnum);
b1=save;
while((b1->num3!=carnum)&&(b1->next==NULL))
{
pre=b1;
b1=b1->next;
}
if(b1->num3==carnum)
{
if(b1==save)
save=save->num3;
else
pre->next=b1->next;
free(b1);
you(struct tikets *save);
}
else
printf("the tikets not been found\n");
goto first;
}


void inquire(struct tikets *save)
{
struct tikets *i1;
char place[10];
int c,k;
printf("which place are you leaving?\n");
gets(place);
c=strcmp(place,save->name);
for(k=0;k<2;k++)
{
if(c==0)
printf(T1,save);
else
printf("can not find it.\n");
}
goto first;
}

void you(struct you1 you2)
{
FILE *fp2;
fp2=fopen("you","w");
printf("please ener your infomation:\n");
printf("name cardnum\n");
scanf("%s%s",you2);
fwrite(you2,N,1,fp2);
fclose(fp2);
printf("book successfully!\n");
goto first;
}
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hustcslhb 2009-05-26
  • 打赏
  • 举报
回复
这个不需要goto的,直接使用while + break 或者do {}while就可以做到,加上个退出的选择菜单就OK了;
goto的label应该是在一个function里面的吧
liliangbao 2009-05-26
  • 打赏
  • 举报
回复
尽可能不要使用goto语句,
再则像1楼所说,goto只能在一个函数内部跳转~
  • 打赏
  • 举报
回复
尽量别用 goto,其实不需要的
机智的呆呆 2009-05-26
  • 打赏
  • 举报
回复
goto只能函数内部跳转。

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧