请帮我抓住这个错误 [英] Please help me to catch this error

查看:57
本文介绍了请帮我抓住这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c编程的新手。这是我的第一个编程项目。

我必须为航空公司预订编写程序。这就是我已经完成的
。但是当它运行时它显示座位数为0和

航班号。也在重复。如果有什么可以告诉我为什么这样请

帮助我。

#include< stdio.h>

#include< ctype.h>

#include< conio.h>

#include< string.h>

void reserv(void);

void add(void);

void view(void);


void main(void)


{

int choice1;


clrscr();

gotoxy(5,5);

printf(" \t\t\tASIAN RAFFAYA AIRLINE RESERVATION\\\
);

printf(" \t\t\t ------ ---------------------------- \\\
");

printf(" \ n" );

printf(" \t\t Main Menue \ n");

printf(" \ nn \ n");


gotoxy(10,10);

printf(" 1。Reservation\ n");

gotoxy(10 ,12);

printf(" 2. Flight List\ n");

gotoxy(10,14);

printf (3。帮助\\ n&n t;);

gotoxy(10,16);

printf(" 4.退出\ n");

printf( \ n \ n \ nn;;

gotoxy(10,20);

printf(" Enter ur choice:");

scanf("%i",& choice1);

printf(" \ n");

printf(" \ n");

printf(" \ n");

开关(choice1)

{

案例1:

reserv();


休息;


案例2:

printf(Flight List \ n);

休息;


案例3:

printf(帮助窗口\ n);

休息;


案例4:

printf("退出从窗口打开\ n");

休息;


默认:

printf(" Invalid\\\
" );


getch();

}

}

/ * ---- --------------------------

预订--------------- --------------- --- * /

void reserv(无效)

{

int choice2;

clrscr();

gotoxy(5,3);

printf(\\\ ASIAN RAFFAYA AIRLINE RESERVATION\\\
);

printf(" \t\t ---------------------------------- \ n") ;

printf(" \ n");

printf(" \t\t Reservation\\\
");

gotoxy(10,10);

printf(" 1。预订座位\ n");

gotoxy(10,12);

printf(" 2.编辑细节\ n");

gotoxy(10,14);

printf(" 3.查看详细信息\ n");

gotoxy(10,16);

printf(" 4.取消预订\ n");

gotoxy(10,18);

printf(" 5.搜索详情\ nn);

gotoxy(10,20);

printf(" 6.Exit\ n);

printf(" \ n\\\
\ n");

gotoxy(10,22);

printf(" Enter ur choice:" );

scanf("%i"& choice2);

printf(" \ n");

printf (" \ n");

printf(" \ n");

开关(choice2)

{

案例1:

add(); / * ----------添加预订----------- * /

休息;


案例2:

printf(" Edit name \\\
"); / * -----------编辑预订--------- * /

休息;


案例3 :

view(); / * -----------查看预订---------- * /

休息;


案例4:

printf(" Delete"); / * ------------删除预订--------- * /

休息;


案例5:

printf(" Search \ n"); / * ------------搜索预订----------

* /

休息;


案例6:

printf(退出窗口\ n);

休息;

默认:

printf(invalid\ n);

}

}

/ * -------------------------------

添加------ ----------------------------------- * /


无效add(void)

{

char name [40];

int res_num = 0,up;

int座位;


char航班[6];

char pass [8];


FILE * sfile ;


if((sfile = fopen(" c:\\ air.dat"," a +"))== NULL)

res_num = 1;


else

{

do {

fscanf(sfile) ,%i \ t%s \ t \%s \ t%i \ t%s

",& res_num,& name,& pass ,& seat,

& flight);


} while(!feof(sfile));

res_num + = 1;


}

clrscr();

gotoxy(5,3);

printf(" \t\ t ASIAN RAFFAYA AIRLINE RESERVATION\\\
;

printf(" \t\t ---------------------- ------------ \\\
");

gotoxy(25,6);

printf(预订座位) ;

printf(" \ n\\\
\\\
\ n");


printf(" Reservation no:%04i" ;,res_num);

printf(" \ nName:");

fflush(stdin);

得到(名字) ;

printf("护照号码:");

fflush(stdin);

得到(通过);

printf(座位数:);

scanf("%i"& seat);


printf (航班:);

fflush(stdin);

得到(航班);

printf(" \ n \ n记录保存!");


fprintf(sfile,"%i \t%s \t \ t%s \ t%i \ t%s

\ n",res_num,name,pass,seat,flight);

fclose(sfile);


do {

printf(" \ nPress [2]进入预订:");

scanf("%i",& up);

if(up!= 2)

printf(" Invalid Entry");

} while(up!= 2);

reserv();


}

/ * ---------------------- -view

预订------------------------------------ * /

void view(void)

{

char name [40];

int res_num,up;

int seat;

char flight [6];

char parse [8];

FILE * sfile;

clrscr();


if((sfile = fopen(" c:\\ air.dat"," a +") )== NULL)

printf(文件空!);


其他

{

printf(\\\ ASIAN RAFFAYA AIRLINE RESERVATION\ n);

printf(" \t\t -------- -------------------------- \\ n");

printf(" \ n \ n No Name \\\ NRIC \t No.of seat \t Flight \ n);

printf(" ---------------------------------------- --------- \ n");


while(!feof(sfile))

{

fscanf(sfile,"%04i \t%s \t \ t%s \ t%i \t

%s"& res_num,& name ,& parse,& seat,& flight);

if(feof(sfile))

休息;


printf("%04i \t%s \t\t%s \t%i \ t%s

\ n",res_num,name,parse,seat ,航班);

}

}


fclose(sfile);


执行{

printf(&\\; \ n\\\
\\\
Press [2]进入预订:");

scanf("%i" ;,& up);

if(up!= 2)

printf(Invalid Entry);

} while( up!= 2);

reserv();


}

I''m newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
void reserv(void);
void add(void);
void view(void);

void main(void)

{
int choice1;

clrscr();
gotoxy(5,5);
printf("\t\t\tASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t\t----------------------------------\n");
printf("\n");
printf("\t\t Main Menue\n");
printf("\n\n");

gotoxy(10,10);
printf("1. Reservation\n");
gotoxy(10,12);
printf("2. Flight List\n");
gotoxy(10,14);
printf("3. Help\n");
gotoxy(10,16);
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);
printf("Enter ur choice: ");
scanf("%i",&choice1);
printf("\n");
printf("\n");
printf("\n");
switch(choice1)
{
case 1:
reserv();

break;

case 2:
printf("Flight List\n");
break;

case 3:
printf("Helping window\n");
break;

case 4:
printf("Exit from the window\n");
break;

default:
printf("Invalid\n");

getch();
}
}
/*------------------------------
reservation---------------------------------*/
void reserv(void)
{
int choice2;
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);
printf("1. Booking a seat\n");
gotoxy(10,12);
printf("2. Edit details\n");
gotoxy(10,14);
printf("3. View Details\n");
gotoxy(10,16);
printf("4. Cancel Reservation\n");
gotoxy(10,18);
printf("5. Search Details\n");
gotoxy(10,20);
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);
printf("Enter ur choice: ");
scanf("%i",&choice2);
printf("\n");
printf("\n");
printf("\n");
switch(choice2)
{
case 1:
add(); /*----------add reservation-----------*/
break;

case 2:
printf("Edit name\n"); /*-----------edit reservation---------*/
break;

case 3:
view(); /*-----------view reservation----------*/
break;

case 4:
printf("Delete"); /*------------delete reservation---------*/
break;

case 5:
printf("Search \n"); /*------------search reservation----------
*/
break;

case 6:
printf("Exit from the window\n");
break;

default:
printf("invalid\n");
}
}
/*-------------------------------
Add-----------------------------------------*/

void add(void)
{
char name[40];
int res_num=0,up;
int seat;

char flight[6];
char pass[8];

FILE*sfile;

if((sfile=fopen("c:\\air.dat","a+"))==NULL)
res_num=1;

else
{
do{
fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s
",&res_num,&name,&pass,&seat,
&flight);

}while(!feof(sfile));
res_num+=1;

}
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);
printf("Booking a seat");
printf("\n\n\n\n");

printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);
gets(name);
printf("passport no : ");
fflush(stdin);
gets(pass);
printf("number of seats: ");
scanf("%i",&seat);

printf("flight : ");
fflush(stdin);
gets(flight);
printf("\n\n Record Saved!");

fprintf(sfile,"%i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,seat,flight);
fclose(sfile);

do{
printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();

}
/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;
clrscr();

if((sfile=fopen("c:\\air.dat","a+"))==NULL)
printf("File Empty!");

else
{
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n No Name\t\t NRIC \t No.of seats \t Flight\n");
printf("-------------------------------------------------\n");

while(!feof(sfile))
{
fscanf(sfile,"%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&parse,&seat,&flight);
if(feof(sfile))
break;

printf("%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,parse,seat,flight);
}
}

fclose(sfile);

do{
printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();

}

推荐答案

2月27日下午2:53,Amali < amalikarunanay ... @ gmail.comwrote:
On Feb 27, 2:53 pm, "Amali" <amalikarunanay...@gmail.comwrote:

我是c编程的新手。这是我的第一个编程项目。

我必须为航空公司预订编写程序。这就是我已经完成的
。但是当它运行时它显示座位数为0和

航班号。也在重复。如果有什么可以告诉我为什么这样请

帮助我。


#include< stdio.h>

#include< ctype .h>

#include< conio.h>

#include< string.h>

void reserv(void);

void add(void);

void view(void);


void main(void)


{

int choice1;


clrscr();

gotoxy(5,5);

printf(" \t\t\tASIAN RAFFAYA AIRLINE RESERVATION\ n);

printf(" \t\t\t-- -------------------------------- \\\
");

printf(" \ n");

printf(" \t\t Main Menue \ n");

printf(" \ n \ n" ;);


gotoxy(10,10);

printf(" 1。Reservation\\\
");

gotoxy(10,12);

printf(" 2. Flight List\ n");

gotoxy(10,14);

printf(" 3。帮助\ n");

gotoxy(10,16);

printf(" 4.退出\ n");

printf(" \ n\\\
\ n");

gotoxy(10,20);

printf(" Enter ur choice:" );

scanf("%i"& choice1);

printf(" \ n");

printf (" \ n");

printf(" \ n");

开关(choice1)

{

案例1:

reserv();


休息;


案例2:

printf(Flight List \ n);

休息;


案例3:

printf(帮助窗口\ n);

休息;


案例4:

printf(从窗口退出\ n);

休息;


默认:

printf(" ;无效\ n");


getch();

}}


/ * - ----------------------------

预订------------- -------------------- * /

void reserv(无效)

{

int choice2;

clrscr();

gotoxy(5,3);

printf(" \t\ t ASIAN RAFFAYA AIRLINE RESERVATION\\\
;

printf(" \t\t ---------------------- ------------ \\\
及现状t;);

printf(" \ n");

printf(" \t\t Reservation\\\
");

gotoxy(10,10);

printf(" 1。预订座位\ n");

gotoxy(10,12);

printf(" 2.编辑细节\ n");

gotoxy(10,14);

printf(" 3.查看详细信息\ n");

gotoxy(10,16);

printf(" 4.取消预订\ n");

gotoxy(10,18);

printf(" 5.搜索详情\ nn);

gotoxy(10,20);

printf(" 6.Exit\ n);

printf(" \ n\\\
\ n");

gotoxy(10,22);

printf(" Enter ur choice:" );

scanf("%i"& choice2);

printf(" \ n");

printf (" \ n");

printf(" \\\
" ;);

开关(选择2)

{

案例1:

add(); / * ----------添加预订----------- * /

休息;


案例2:

printf(" Edit name \\\
"); / * -----------编辑预订--------- * /

休息;


案例3 :

view(); / * -----------查看预订---------- * /

休息;


案例4:

printf(" Delete"); / * ------------删除预订--------- * /

休息;


案例5:

printf(" Search \ n"); / * ------------搜索预订----------

* /

休息;


案例6:

printf(退出窗口\ n);

休息;

默认:

printf(" invalid\\\
");


}}


/ * -------------------------------

添加------ ----------------------------------- * /


无效add(void)

{

char name [40];

int res_num = 0,up;

int座位;


char航班[6];

char pass [8];


FILE * sfile ;


if((sfile = fopen(" c:\\ air.dat"," a +"))== NULL)

res_num = 1;


其他

{

do {

fscanf(sfile,"%i \%s \ t \ t%s \ t%我\\%s

",& res_num,& name,& pass,& seat,

& flight);


} while(!feof(sfile));

res_num + = 1;


}

clrscr();

gotoxy(5,3);

printf(" \t\ t ASIAN RAFFAYA AIRLINE RESERVATION\\\
" );

printf(" \t\t ------------------------------ ---- \ n");

gotoxy(25,6);

printf(预订座位);

printf(" \ n \ n \ n \\ n \\ n \\ n \\ n \\ n");


printf("预订编号:%04i",res_num);

printf(" \ name:");

fflush(stdin);

得到(名字);

printf("护照号码:");

fflush(stdin);

得到(通过);

printf(座位数:);

scanf("%i",& seat);


printf(" flight:");

fflush(stdin);

得到(航班);


printf(" \ n \ nn Record Saved!");


fprintf(sfile,"%i \ t%s \ t \%s \ t%i \ t%s

\ n",res_num,name,pass,seat,flight);

fclose( sfile);


做{

printf(&\\; \ nPress [2]去预订:");

scanf("%i"& up);

if(up!= 2)

printf(" Invalid Entry");

} while(up!= 2);


reserv();


}


/ * ------------------- ----查看

预订------------------------------------ * /

无视图(无效)

{

char name [40];

int res_num,up ;

int seat;

char flight [6];

char parse [8];

FILE * sfile;


clrscr();


if((sfile = fopen(" c:\\ air.dat", a +))== NULL)

printf(文件空!);


其他

{

printf(&\\; \\\ ASIAN RAFFAYA AIRLINE RESERVATION\ n);

printf(" \t\t - --------------------------------- \\\
");

printf(" ; \ n \ nn No Name \\\\ NRIC \t座位数\t Flight \ nn);

的printf(QUOT; ---------------------------------------------- --- \ n");


while(!feof(sfile))

{

fscanf(sfile, "%04i \t%s \t \ t%s \ t%i \ t

%s"& res_num,& name,& parse,& ;座位,&航班);

if(feof(sfile))

休息;


printf("% 04i \t%s \t\t%s \t%i \ t%s

\ n",res_num,name,parse,seat,flight);

}

}


fclose(sfile);


do {

printf(" \ n\\\
\\\
Press [2]进入预订:");

scanf("%i"& up) ;

if(up!= 2)

pri ntf(无效条目);

} while(up!= 2);


reserv();


} - 隐藏引用的文字 -


- 显示引用的文字 -
I''m newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.

#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
void reserv(void);
void add(void);
void view(void);

void main(void)

{
int choice1;

clrscr();
gotoxy(5,5);
printf("\t\t\tASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t\t----------------------------------\n");
printf("\n");
printf("\t\t Main Menue\n");
printf("\n\n");

gotoxy(10,10);
printf("1. Reservation\n");
gotoxy(10,12);
printf("2. Flight List\n");
gotoxy(10,14);
printf("3. Help\n");
gotoxy(10,16);
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);
printf("Enter ur choice: ");
scanf("%i",&choice1);
printf("\n");
printf("\n");
printf("\n");
switch(choice1)
{
case 1:
reserv();

break;

case 2:
printf("Flight List\n");
break;

case 3:
printf("Helping window\n");
break;

case 4:
printf("Exit from the window\n");
break;

default:
printf("Invalid\n");

getch();
}}

/*------------------------------
reservation---------------------------------*/
void reserv(void)
{
int choice2;
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);
printf("1. Booking a seat\n");
gotoxy(10,12);
printf("2. Edit details\n");
gotoxy(10,14);
printf("3. View Details\n");
gotoxy(10,16);
printf("4. Cancel Reservation\n");
gotoxy(10,18);
printf("5. Search Details\n");
gotoxy(10,20);
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);
printf("Enter ur choice: ");
scanf("%i",&choice2);
printf("\n");
printf("\n");
printf("\n");
switch(choice2)
{
case 1:
add(); /*----------add reservation-----------*/
break;

case 2:
printf("Edit name\n"); /*-----------edit reservation---------*/
break;

case 3:
view(); /*-----------view reservation----------*/
break;

case 4:
printf("Delete"); /*------------delete reservation---------*/
break;

case 5:
printf("Search \n"); /*------------search reservation----------
*/
break;

case 6:
printf("Exit from the window\n");
break;

default:
printf("invalid\n");

}}

/*-------------------------------
Add-----------------------------------------*/

void add(void)
{
char name[40];
int res_num=0,up;
int seat;

char flight[6];
char pass[8];

FILE*sfile;

if((sfile=fopen("c:\\air.dat","a+"))==NULL)
res_num=1;

else
{
do{
fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s
",&res_num,&name,&pass,&seat,
&flight);

}while(!feof(sfile));
res_num+=1;

}

clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);
printf("Booking a seat");
printf("\n\n\n\n");

printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);
gets(name);
printf("passport no : ");
fflush(stdin);
gets(pass);
printf("number of seats: ");
scanf("%i",&seat);

printf("flight : ");
fflush(stdin);
gets(flight);

printf("\n\n Record Saved!");

fprintf(sfile,"%i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,seat,flight);
fclose(sfile);

do{
printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);

reserv();

}

/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;

clrscr();

if((sfile=fopen("c:\\air.dat","a+"))==NULL)
printf("File Empty!");

else
{
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n No Name\t\t NRIC \t No.of seats \t Flight\n");
printf("-------------------------------------------------\n");

while(!feof(sfile))
{
fscanf(sfile,"%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&parse,&seat,&flight);
if(feof(sfile))
break;

printf("%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,parse,seat,flight);
}
}

fclose(sfile);

do{
printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);

reserv();

}- Hide quoted text -

- Show quoted text -



我认为我的问题是补充的并查看功能。

请帮帮我。

I think my problem is in add and view functions.
Please help me.


Amali说:
Amali said:

我是c编程的新手。这是我的第一个编程项目。

我必须为航空公司预订编写程序。这就是我已经完成的
。但是当它运行时它显示座位数为0和

航班号。也在重复。如果有任何可以告诉我为什么这样请

帮助我。
I''m newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.



< snip>


main函数返回int,而不是void。 scanf函数返回一个

有用值,您应该检查它。 fflush的行为仅为为输出或更新而打开的流定义,而不是为输入定义。

获取功能是危险的,永远不应该被使用。使用fgets

(并阅读您的文档以了解它的工作原理)。你的
fscanf循环会一直覆盖先前读取的值,直到它到达文件的

结尾,这几乎肯定不是你想要的 - 查询

数组。 feof函数几乎从不是控制

文件读取循环的正确方法。检查文件读取功能的返回值




修复这些,并告诉我们是否能解决问题。
< br $>
-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

<snip>

The main function returns int, not void. The scanf function returns a
useful value, which you should check. The behaviour of fflush is
defined only for streams open for output or update, not for input. The
gets function is dangerous and should never, ever be used. Use fgets
instead (and read your documentation to understand how it works). Your
fscanf loop keeps overwriting previously-read values until it hits the
end of the file, which almost certainly is not what you want - look up
arrays. The feof function is almost never the right way to control a
file-reading loop. Check the return value of the file-reading function
instead.

Fix those, and let us know whether that fixed your problem.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


2月27日下午1:59,Amali ; < amalikarunanay ... @ gmail.comwrote:
On Feb 27, 1:59 pm, "Amali" <amalikarunanay...@gmail.comwrote:

2月27日下午2:53,Amali < amalikarunanay ... @ gmail.comwrote:
On Feb 27, 2:53 pm, "Amali" <amalikarunanay...@gmail.comwrote:

我是c编程的新手。这是我的第一个编程项目。

我必须为航空公司预订编写程序。这就是我已经完成的
。但是当它运行时它显示座位数为0和

航班号。也在重复。如果有任何可以告诉我为什么这样请

帮助我。
I''m newdie in c programming. this is my first project in programming.
I have to write a program for a airline reservation. this is what i
have done yet. but when it runs it shows the number of seats as 0 and
the flight no. is also repeating. If any can tell why is this please
help me.


#include< stdio.h>

#include< ctype.h>

#include< conio.h>

#include< string.h>

void reserv(void);

void add(void);

void view(void);
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
void reserv(void);
void add(void);
void view(void);


void main(void)
void main(void)


{

int choice1;
{
int choice1;


clrscr();

gotoxy(5,5);

printf(" ; \\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ ------------------------ \\\
");

printf(" \ n");

printf(" \t\t Main Menue \ n");

printf(" \ n\ n");
clrscr();
gotoxy(5,5);
printf("\t\t\tASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t\t----------------------------------\n");
printf("\n");
printf("\t\t Main Menue\n");
printf("\n\n");


gotoxy(10,10);

printf(" 1。Reservation\\\
");

gotoxy(10,12);

printf(" 2. Flight List\ n");

gotoxy(10,14);

printf(" 3.'Help\ n);

gotoxy(10,16);

printf(" 4。退出\ n");

printf(" \ n\\\
\ n");

gotoxy(10,20);

printf("输入你的选择:");

scanf("%i",& choice1);

printf(" \\ \\ n");

printf(" \ n");

printf(" \ n");

开关(选择1)

{

案例1:

reserv();
gotoxy(10,10);
printf("1. Reservation\n");
gotoxy(10,12);
printf("2. Flight List\n");
gotoxy(10,14);
printf("3. Help\n");
gotoxy(10,16);
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);
printf("Enter ur choice: ");
scanf("%i",&choice1);
printf("\n");
printf("\n");
printf("\n");
switch(choice1)
{
case 1:
reserv();


break;
break;


case 2:

printf(" Flight List\ n);

休息;
case 2:
printf("Flight List\n");
break;


案例3:

printf(帮助窗口\ n);

休息;
case 3:
printf("Helping window\n");
break;


case 4:

printf("从窗口退出\ n);

休息;
case 4:
printf("Exit from the window\n");
break;


默认值:

printf(" Invalid\\\
");
default:
printf("Invalid\n");


getch();
getch();
}}


/ * ------------------------------

预订----- ---------------------------- * /

void reserv(无效)

{

int choice2;

clrscr();

gotoxy(5,3);

printf( \t\t ASIAN RAFFAYA AIRLINE RESERVATION\\\
);

printf(" \t\t -------------- -------------------- \\\
");

printf(" \ n");

printf(" \t\t Reservation\\\
");

gotoxy(10,10);

printf(" 1。预订a seat \ n");

gotoxy(10,12);

printf(&q uot; 2.编辑细节\ n");

gotoxy(10,14);

printf(" 3。查看详细信息\ n");

gotoxy(10,16);

printf(" 4.取消预订\ n");

gotoxy(10,18);

printf(" 5.搜索详情\ n");

gotoxy(10,20);

printf(" 6. Exit.\
");

printf(" \ n\\\
\ n");

gotoxy(10,22);

printf("输入你的选择:");

scanf("%i",& choice2);

printf(" \ n");

printf(" \ n");

printf(" \ n" );

开关(选择2)

{

案例1:

add(); / * ----------添加预订----------- * /

休息;
/*------------------------------
reservation---------------------------------*/
void reserv(void)
{
int choice2;
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);
printf("1. Booking a seat\n");
gotoxy(10,12);
printf("2. Edit details\n");
gotoxy(10,14);
printf("3. View Details\n");
gotoxy(10,16);
printf("4. Cancel Reservation\n");
gotoxy(10,18);
printf("5. Search Details\n");
gotoxy(10,20);
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);
printf("Enter ur choice: ");
scanf("%i",&choice2);
printf("\n");
printf("\n");
printf("\n");
switch(choice2)
{
case 1:
add(); /*----------add reservation-----------*/
break;


case 2:

printf(" Edit name \\\
"); / * -----------编辑预订--------- * /

休息;
case 2:
printf("Edit name\n"); /*-----------edit reservation---------*/
break;


case 3:

view(); / * -----------查看预订---------- * /

休息;
case 3:
view(); /*-----------view reservation----------*/
break;


case 4:

printf(" Delete"); / * ------------删除预订--------- * /

休息;
case 4:
printf("Delete"); /*------------delete reservation---------*/
break;


case 5:

printf(" Search \ n"); / * ------------搜索预订----------

* /

休息;
case 5:
printf("Search \n"); /*------------search reservation----------
*/
break;


案例6:

printf(从窗口退出\ n);

休息;
case 6:
printf("Exit from the window\n");
break;


默认值:

printf(" invalid\\\
");
default:
printf("invalid\n");


}}
}}


/ * ------ -------------------------

添加---------------- ------------------------- * /
/*-------------------------------
Add-----------------------------------------*/


void add( void)

{

char name [40];

int res_num = 0,up;

int seat ;
void add(void)
{
char name[40];
int res_num=0,up;
int seat;


char flight [6];

char pass [8];
char flight[6];
char pass[8];


FILE * sfile;
FILE*sfile;


if((sfile = fopen(" c:\\ air.dat"," a +"))== NULL)

res_num = 1;
if((sfile=fopen("c:\\air.dat","a+"))==NULL)
res_num=1;


else

{

do {

fscanf( sfile,"%i \ t%s \ t \ t%s \ t%i \t%s

",& res_num,& name,&通过,和座位,

& flight);
else
{
do{
fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s
",&res_num,&name,&pass,&seat,
&flight);


} while(!feof(sfile));

res_num + = 1;
}while(!feof(sfile));
res_num+=1;


}
}


clrscr();

gotoxy(5,3);

printf(\\\ ASIAN RAFFAYA AIRLINE RESERVATION\\\
);

printf(" \t\t ---------------------------------- \ n");

gotoxy(25,6);

printf(预订座位);

printf(" \ n\\\
\ n \\\
");
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);
printf("Booking a seat");
printf("\n\n\n\n");


printf(" Reservation no:%04i",res_num);

printf(" \ nnName) :");

fflush(stdin);

得到(名字);

printf(" passport no:");

fflush(stdin);

得到(通过);

printf(座位数:);

scanf("%i",& seat);
printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);
gets(name);
printf("passport no : ");
fflush(stdin);
gets(pass);
printf("number of seats: ");
scanf("%i",&seat);


printf(" flight:");

fflush(stdin);

得到(飞行);
printf("flight : ");
fflush(stdin);
gets(flight);


printf(" \ n \ nn Record Saved!");
printf("\n\n Record Saved!");


fprintf(sfile,"%i \t%s \t \ t%s \ t%i \ t% s

\n",res_num,name,pass,seat,flight);

fclose(sfile);
fprintf(sfile,"%i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,seat,flight);
fclose(sfile);

\t
\t\t\t\t do{

printf("\nPress [2] to go to reservation: ");

scanf("%i",&up);

if(up!=2)

printf("Invalid Entry");

}while(up!=2);
do{
printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);

\t
\t\t\t\t reserv();
reserv();

\t
\t\t\t\t }
}

\t
\t\t\t\t /*-----------------------view

reservations------------------------------------*/

void view(void)

{

char name[40];

int res_num,up;

int seat;

char flight[6];

char parse[8];

FILE*sfile;
/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;

\t
\t\t\t\t clrscr();
clrscr();

\t
\t\t\t\t if((sfile=fopen("c:\\air.dat","a+"))==NULL)

printf("File Empty!");
if((sfile=fopen("c:\\air.dat","a+"))==NULL)
printf("File Empty!");

\t
\t\t\t\t else

{

printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");

printf("\t\t ----------------------------------\n");

printf("\n\n No Name\t\t NRIC \t No.of seats \t Flight\n");

printf("-------------------------------------------------\n");
else
{
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n No Name\t\t NRIC \t No.of seats \t Flight\n");
printf("-------------------------------------------------\n");

\t
\t\t\t\t while(!feof(sfile))

{

fscanf(sfile,"%04i \t%s \t\t%s \t%i \t

%s",&res_num,&name,&parse,&seat,&flight);

if(feof(sfile))

break;
while(!feof(sfile))
{
fscanf(sfile,"%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&parse,&seat,&flight);
if(feof(sfile))
break;

\t
\t\t\t\t printf("%04i \t%s \t\t%s \t%i \t%s

\n",res_num,name,parse,seat,flight);

}

}
printf("%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,parse,seat,flight);
}
}

\t
\t\t\t\t fclose(sfile);
fclose(sfile);

\t
\t\t\t\t do{

printf("\n\n\nPress [2] to go to reservation: ");

scanf("%i",&up);

if(up!=2)

printf("Invalid Entry");

}while(up!=2);
do{
printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);

\t
\t\t\t\t reserv();
reserv();

\t
\t\t\t\t }- Hide quoted text -
}- Hide quoted text -

\t
\t\t\t\t - Show quoted text -
- Show quoted text -



I think my problem is in add and view functions.

Please help me.


I think my problem is in add and view functions.
Please help me.



Here are my comments.


(1) conio.h, clrscr, gotoxy [and I think getch() too] are not

portable. They are not working in my gcc compiler.

(2) When you open a file in a+ mode, by default file stream is at the

end thats the reason you are not able to read the records or view the

records as stream is already at the end. Go here for details on fopen.

http://www.codecogs.com/reference/st...hp?alias=fopen


When I changed the code to open the file in "r" mode I could view the

recodds. IMHO it would be better if you use just "\t" as delimiter and

not some complex string.


(3) fflush does not work on input streams. So fix it before you can

add.


Again many a times debugging by self gives more revelations about the

mistake and the learning from this way is going to be more permanent!


Arvind

purohit underscore arvind 8 yahoo dot com

Here are my comments.

(1) conio.h, clrscr, gotoxy [and I think getch() too] are not
portable. They are not working in my gcc compiler.
(2) When you open a file in a+ mode, by default file stream is at the
end thats the reason you are not able to read the records or view the
records as stream is already at the end. Go here for details on fopen.

http://www.codecogs.com/reference/st...hp?alias=fopen

When I changed the code to open the file in "r" mode I could view the
recodds. IMHO it would be better if you use just "\t" as delimiter and
not some complex string.

(3) fflush does not work on input streams. So fix it before you can
add.

Again many a times debugging by self gives more revelations about the
mistake and the learning from this way is going to be more permanent!

Arvind
purohit underscore arvind 8 yahoo dot com


这篇关于请帮我抓住这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆