Please help me to catch this error

A

Amali

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();

}
 
A

Amali

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.
 
R

Richard Heathfield

Amali said:
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>

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.
 
S

sw_engg

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();

case 2:
printf("Flight List\n");
break;
case 3:
printf("Helping window\n");
break;
case 4:
printf("Exit from the window\n");
break;


/*------------------------------
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.

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/stdio.h/fopen.php?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
 
C

CBFalconer

Amali said:
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)

Well, so far you have used a nonexistent header (conio.h) and
failed to correctly declare main as returning an int. No further
reading need be done.
 
A

Amali

Well, so far you have used a nonexistent header (conio.h) and
failed to correctly declare main as returning an int. No further
reading need be done.

- Hide quoted text -

- Show quoted text -

Thank u very much!!!!!
 
P

Peter Shaggy Haywood

Groovy hepcat Amali was jivin' on 27 Feb 2007 00:53:59 -0800 in
comp.lang.c.
Please help me to catch this error's a cool scene! Dig it!
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>

Non-standard, non-portable, useless header.
#include<string.h>
void reserv(void);
void add(void);
void view(void);

void main(void)

That should be int main(void). The fact that you have used void
main() indicates to me that you have not lurked here for any length of
time nor read the FAQ. This is very rude! When entering a newsgroup
for the first time it is customary (and expected) to read a month or
two of posts before posting (lurk) and also to read the newsgroup's
FAQ list. Please don't post to comp.lang.c again until you have done
so. You'll find the FAQ at http://www.eskimo.com/~scs/C-faq/top.html.
{
int choice1;

clrscr();
gotoxy(5,5);

Non-standard, non-portable, useless function calls.
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);

Non-standard, non-portable, useless function call.
printf("1. Reservation\n");
gotoxy(10,12);

Non-standard, non-portable, useless function call.
printf("2. Flight List\n");
gotoxy(10,14);

Non-standard, non-portable, useless function call.
printf("3. Help\n");
gotoxy(10,16);

Non-standard, non-portable, useless function call.
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);

Non-standard, non-portable, useless function call.
printf("Enter ur choice: ");
scanf("%i",&choice1);

The FAQ will tell you why scanf() is best to avoid, and what to use
instead.
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();

Non-standard, non-portable, useless function call.
}
}
/*------------------------------
reservation---------------------------------*/
void reserv(void)
{
int choice2;
clrscr();
gotoxy(5,3);

Non-standard, non-portable, useless function calls.
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);

Non-standard, non-portable, useless function call.
printf("1. Booking a seat\n");
gotoxy(10,12);

Non-standard, non-portable, useless function call.
printf("2. Edit details\n");
gotoxy(10,14);

Non-standard, non-portable, useless function call.
printf("3. View Details\n");
gotoxy(10,16);

Non-standard, non-portable, useless function call.
printf("4. Cancel Reservation\n");
gotoxy(10,18);

Non-standard, non-portable, useless function call.
printf("5. Search Details\n");
gotoxy(10,20);

Non-standard, non-portable, useless function call.
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);

Non-standard, non-portable, useless function call.
printf("Enter ur choice: ");
scanf("%i",&choice2);

See above.
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)

If the file can be opened, it is set to append, for writing at the
end, and possibly reading at the end. Before you can be sure of
reading anything useful, you may need to reposition the file position
indicator for this stream.
res_num=1;

else
{
do{
fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s

All those tab escape sequences and spaces in the format string are
not necessary. If you need to skip white space, a single space will do
in the format string.
Also, be careful of posting long lines here. They have a tendancy to
wrap. You can break long strings up into shorter ones accross multiple
lines, and they will be concatenated by the preprocessor. For example:

"This is a string. "
"And this is part of the same string, "
"even though it's broken into multiple "
"string literals."

The above four string literals will be concatenated into a single
string.
",&res_num,&name,&pass,&seat,

Since name, pass and flight are arrays of char and decay into
pointers to their initial elements, the & operators applied these are
entirely superfluous. In fact, they're just plain wrong. Leave them
out.
Also, you'll no doubt want to limit the number of characters that
can be stored in each of those arrays. So you're going to need field
width specifiers in your format string.
&flight);

You're not doing anything with the data you've just read in. Why
bother reading it in, then?
}while(!feof(sfile));

Using feof() isn't the best way of controlling an input loop. The
FAQ says why.
Remember, fscanf() returns a value. Use that to control your loop.
For example:

while(5 == fscanf(sfile, "%i %39s %7s %i %5s",
&res_name, name, pass, &seat, flight))
;
res_num+=1;

}

Here ends your else clause. What follows is, then, always executed,
regardless of the if(...) statement above. Even things that rely on
the else clause being executed, such as closing the file (since the
else clause being executed relys on the file being successfully
opened).
clrscr();
gotoxy(5,3);

Non-standard, non-portable, useless function calls.
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);

Non-standard, non-portable, useless function call.
printf("Booking a seat");
printf("\n\n\n\n");

printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);

BANG! Undefined behaviour! fflush() is defined to flush output to an
output stream. Passing an input stream, such as stdin, to fflush()
causes undefined behaviour.
gets(name);

NEVER, never, never, never, never use gets(). It can never be used
safely. Read the FAQ, and use fgets() instead.
printf("passport no : ");
fflush(stdin);
gets(pass);

See above.
printf("number of seats: ");
scanf("%i",&seat);

See above.
printf("flight : ");
fflush(stdin);
gets(flight);

See above.
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);

See above.
do{
printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);

See above.
if(up!=2)
printf("Invalid Entry");
}while(up!=2);


reserv();

You're calling reserv() here? Are you sure that's what you want to
do? I see no reason reserv() should be recursive. Perhaps you just
want to return here, which would put you back in reserv() at the point
after add() was called.
}
/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;

clrscr();

Non-standard, non-portable, useless function call.
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))

See above.
{
fscanf(sfile,"%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&parse,&seat,&flight);

See above.
if(feof(sfile))
break;

If you'd use fscanf()'s return value to control the loop, you
wouldn't have to bother with this needless feof() test here. You
wouldn't need to bother with feof() at all. See the FAQ.
printf("%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,parse,seat,flight);

Poor indentation, confusing, making it harder to read and understand
the code. Please indent consistently. Don't mix tabs and spaces,
especially in Usenet. In fact, spaces are much prefered.
Also, see above about line wrapping and string concatenation.
}
}

fclose(sfile);

Since this fclose() call is outside the else clause of the if(...)
statement, it is executed whether the file could be opened or not.
BANG! Undefined behaviour again, if the file failed to open!
do{
printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);

What's all this rigmarole in aide of? Why annoy the user by making
him/her press "2" and "Enter" (without telling him/her about the
latter)? Just return. If you must wait, then just wait for "Enter".
For example:

printf("Press \"Enter\" to continue...\n");
skip2nl(stdin);

where skip2nl() could be defined as:

void skip2nl(FILE *fp)
{
int c;

while(EOF != (c = fgetc(fp)) && '\n' != c)
;
}

This would skip all input up to EOF or a newline in a given input
stream. This could be a very useful function, not just for waiting for
"Enter" to be pressed. But all your fflush(stdin)s can be replaced
with skip2nl(stdin). In fact, you could even make it better by
returning a value, so it could then indicate whether EOF has been
read. All you'd need to do is have it return c. Then a calling
function could test the return value for EOF, and take some
appropriate action. (But I digress.)
reserv();

Again you're recursing into reserv(). What for? No doubt you really
just need to return.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
A

Amali

Groovy hepcat Amali was jivin' on 27 Feb 2007 00:53:59 -0800 in
comp.lang.c.
Please help me to catch this error's a cool scene! Dig it!
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>

Non-standard, non-portable, useless header.
#include<string.h>
void reserv(void);
void add(void);
void view(void);
void main(void)

That should be int main(void). The fact that you have used void
main() indicates to me that you have not lurked here for any length of
time nor read the FAQ. This is very rude! When entering a newsgroup
for the first time it is customary (and expected) to read a month or
two of posts before posting (lurk) and also to read the newsgroup's
FAQ list. Please don't post to comp.lang.c again until you have done
so. You'll find the FAQ athttp://www.eskimo.com/~scs/C-faq/top.html.
{
int choice1;
clrscr();
gotoxy(5,5);

Non-standard, non-portable, useless function calls.
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);

Non-standard, non-portable, useless function call.
printf("1. Reservation\n");
gotoxy(10,12);

Non-standard, non-portable, useless function call.
printf("2. Flight List\n");
gotoxy(10,14);

Non-standard, non-portable, useless function call.
printf("3. Help\n");
gotoxy(10,16);

Non-standard, non-portable, useless function call.
printf("4. Exit\n");
printf("\n\n\n");
gotoxy(10,20);

Non-standard, non-portable, useless function call.
printf("Enter ur choice: ");
scanf("%i",&choice1);

The FAQ will tell you why scanf() is best to avoid, and what to use
instead.
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;

getch();

Non-standard, non-portable, useless function call.
}
}
/*------------------------------
reservation---------------------------------*/
void reserv(void)
{
int choice2;
clrscr();
gotoxy(5,3);

Non-standard, non-portable, useless function calls.
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Reservation\n");
gotoxy(10,10);

Non-standard, non-portable, useless function call.
printf("1. Booking a seat\n");
gotoxy(10,12);

Non-standard, non-portable, useless function call.
printf("2. Edit details\n");
gotoxy(10,14);

Non-standard, non-portable, useless function call.
printf("3. View Details\n");
gotoxy(10,16);

Non-standard, non-portable, useless function call.
printf("4. Cancel Reservation\n");
gotoxy(10,18);

Non-standard, non-portable, useless function call.
printf("5. Search Details\n");
gotoxy(10,20);

Non-standard, non-portable, useless function call.
printf("6. Exit\n");
printf("\n\n\n");
gotoxy(10,22);

Non-standard, non-portable, useless function call.
printf("Enter ur choice: ");
scanf("%i",&choice2);

See above.
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)

If the file can be opened, it is set to append, for writing at the
end, and possibly reading at the end. Before you can be sure of
reading anything useful, you may need to reposition the file position
indicator for this stream.
res_num=1;
else
{
do{
fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s

All those tab escape sequences and spaces in the format string are
not necessary. If you need to skip white space, a single space will do
in the format string.
Also, be careful of posting long lines here. They have a tendancy to
wrap. You can break long strings up into shorter ones accross multiple
lines, and they will be concatenated by the preprocessor. For example:

"This is a string. "
"And this is part of the same string, "
"even though it's broken into multiple "
"string literals."

The above four string literals will be concatenated into a single
string.
",&res_num,&name,&pass,&seat,

Since name, pass and flight are arrays of char and decay into
pointers to their initial elements, the & operators applied these are
entirely superfluous. In fact, they're just plain wrong. Leave them
out.
Also, you'll no doubt want to limit the number of characters that
can be stored in each of those arrays. So you're going to need field
width specifiers in your format string.
&flight);

You're not doing anything with the data you've just read in. Why
bother reading it in, then?
}while(!feof(sfile));

Using feof() isn't the best way of controlling an input loop. The
FAQ says why.
Remember, fscanf() returns a value. Use that to control your loop.
For example:

while(5 == fscanf(sfile, "%i %39s %7s %i %5s",
&res_name, name, pass, &seat, flight))
;
res_num+=1;

Here ends your else clause. What follows is, then, always executed,
regardless of the if(...) statement above. Even things that rely on
the else clause being executed, such as closing the file (since the
else clause being executed relys on the file being successfully
opened).
clrscr();
gotoxy(5,3);

Non-standard, non-portable, useless function calls.
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
gotoxy(25,6);

Non-standard, non-portable, useless function call.
printf("Booking a seat");
printf("\n\n\n\n");
printf("Reservation no: %04i ",res_num);
printf("\nName : ");
fflush(stdin);

BANG! Undefined behaviour! fflush() is defined to flush output to an
output stream. Passing an input stream, such as stdin, to fflush()
causes undefined behaviour.
gets(name);

NEVER, never, never, never, never use gets(). It can never be used
safely. Read the FAQ, and use fgets() instead.
printf("passport no : ");
fflush(stdin);
gets(pass);

See above.
printf("number of seats: ");
scanf("%i",&seat);

See above.
printf("flight : ");
fflush(stdin);
gets(flight);

See above.
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);

See above.
do{
printf("\nPress [2] to go to reservation: ");
scanf("%i",&up);

See above.
if(up!=2)
printf("Invalid Entry");
}while(up!=2);
reserv();

You're calling reserv() here? Are you sure that's what you want to
do? I see no reason reserv() should be recursive. Perhaps you just
want to return here, which would put you back in reserv() at the point
after add() was called.
}
/*-----------------------view
reservations------------------------------------*/
void view(void)
{
char name[40];
int res_num,up;
int seat;
char flight[6];
char parse[8];
FILE*sfile;
clrscr();

Non-standard, non-portable, useless function call.
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))

See above.
{
fscanf(sfile,"%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&parse,&seat,&flight);

See above.
if(feof(sfile))
break;

If you'd use fscanf()'s return value to control the loop, you
wouldn't have to bother with this needless feof() test here. You
wouldn't need to bother with feof() at all. See the FAQ.
printf("%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,parse,seat,flight);

Poor indentation, confusing, making it harder to read and understand
the code. Please indent consistently. Don't mix tabs and spaces,
especially in Usenet. In fact, spaces are much prefered.
Also, see above about line wrapping and string concatenation.
fclose(sfile);

Since this fclose() call is outside the else clause of the if(...)
statement, it is executed whether the file could be opened or not.
BANG! Undefined behaviour again, if the file failed to open!
do{
printf("\n\n\nPress [2] to go to reservation: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);

What's all this rigmarole in aide of? Why annoy the user by making
him/her press "2" and "Enter" (without telling him/her about the
latter)? Just return. If you must wait, then just wait for "Enter".
For example:

printf("Press \"Enter\" to continue...\n");
skip2nl(stdin);

where skip2nl() could be defined as:

void skip2nl(FILE *fp)
{
int c;

while(EOF != (c = fgetc(fp)) && '\n' != c)
;

}

This would skip all input up to EOF or a newline in a given input
stream. This could be a very useful function, not just for waiting for
"Enter" to be pressed. But all your fflush(stdin)s can be replaced
with skip2nl(stdin). In fact, you could even make it better by
returning a value, so it could then indicate whether EOF has been
read. All you'd need to do is have it return c. Then a calling
function could test the return value for EOF, and take some
appropriate action. (But I digress.)
reserv();

Again you're recursing into reserv(). What for? No doubt you really
just need to return.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?

Thank u so much. I got kind of idea what r the areas i should study
first. before i haven't any idea about "while(!feof(sfile))" these
kind of things because in the class also we did only typing the
programs in our txt book. So i haven't any idea about some codings.
But now can study and what said and then do it.
 
S

santosh

Amali said:
On Mar 3, 7:36 am, (e-mail address removed) (Peter "Shaggy"
Haywood) wrote:

Thank u so much. I got kind of idea what r the areas i should study
first. before i haven't any idea about "while(!feof(sfile))" these
kind of things because in the class also we did only typing the
programs in our txt book. So i haven't any idea about some codings.
But now can study and what said and then do it.

If you just want to say thank you, you don't need to quote the whole
of the previous article. Some people still have slow modem connections
and they might get annoyed at having to download a 500 kb message just
to find your thanks at the end. If something isn't relavent to your
reply, you can snip it, especially signature blocks that begin after a
'-- '.
 
C

CBFalconer

santosh said:
Amali wrote:



If you just want to say thank you, you don't need to quote the whole
of the previous article. Some people still have slow modem connections
and they might get annoyed at having to download a 500 kb message just
to find your thanks at the end. If something isn't relavent to your
reply, you can snip it, especially signature blocks that begin after a
'-- '.

In addition Amali should refrain from using childish abbreviations,
such as 'u' and 'r', which only serve to make his posts
unintelligible.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
B

Beej Jorgensen

santosh said:
Some people still have slow modem connections and they might get
annoyed at having to download a 500 kb message just to find your thanks
at the end.

And some people with fast connections might still get annoyed at needing
to page down forever. :)

Plus, it's Just Bad Form and violates all the etiquette rules on the
matter, and negates the gains made by quoting in context.

-Beej
 
A

Amali

Amali said:


<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.

I submited my project and its working. I haven't done many things in
the class so i have to do my project accoding to the text book. but
these days i'm studing more about c programming. Please tell me some
links to get tutorial in c programming. Anyway i'll send you my
codings. Thank you.

#include<stdio.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>

/*-----The Prototypes-----*/

void menu(void);
void reserv(void);
void add(void);
void edit(void);
void view(void);
void search(void);
void del(void);
void exit(void);
void help (void);
void fly(void);
void flyadd(void);
void viewfly(void);

/*--------------------------------Welcome---------------------------*/

void main(void)
{
int ans1;

clrscr();
gotoxy(30,8);
printf("WELCOME!!!\n\n");
gotoxy(15,10);
printf("ASIAN RAFFAYA AIRLINE RESERVATION COMPANY");
gotoxy(15,11);
printf("-----------------------------------------");
printf("\n\n\n");

do{
printf("\n\t\tpress [1] to go to Main menu: ");
scanf("%i",&ans1);
if(ans1!=1)
printf("\n\t\tInvalid Entry!\n\n");
}while(ans1!=1);

menu();
}

/*-----------------------Menu---------------------------------*/

void menu(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("\tEnter your choice[1-4]: ");
scanf("%i",&choice1);
printf("\n");


switch(choice1)
{
case 1:
reserv(); /*-----Reservation--*/ break;

case 2:
fly(); /*------Flight menu---*/
break;

case 3:
help(); /*---------help------*/
break;

case 4:
exit(); /*--------exit----------*/
break;

default:
printf("\t\tInvalid Entry!\n");
printf("\t\tEnter your choice[1-4]: ");
scanf("%i",&choice1);
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 your choice[1-6]: ");
scanf("%i",&choice2);
printf("\n");
printf("\n");

switch(choice2)
{
case 1:
add(); /*--add reservation--*/

break;
case 2:
edit(); /*-----------edit reservation-------------*/
break;

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

case 4:
del(); /*------------delete reservation---------*/
break;

case 5:
search(); /*------------search reservation---------*/
break;

case 6:
menu(); /*-------------Back to menu---------------
*/
break;

default:
printf("\t\tInvalid Entry!\n\n");
printf("\tEnter your choice[1-6]: ");
scanf("%i",&choice2);

}
}
/*-------------------------------
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.txt","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();

}


/*-------------------------------Edit
Details---------------------------------*/
void edit(void)
{

char name[40],Target[40];
int res_num,Found=0;
int seat,up;
char flight[6];
char pass[8];


FILE *temp=fopen("c:\\temp.txt","w");
FILE *sfile=fopen("c:\\air.txt","r");

clrscr();

printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n\t\t Edit Details");
printf("\n\t\t -----------------");
printf("\n\n\tEnter name to edit: ");
fflush(stdin);
gets(Target);

while(!feof(sfile))
{
fscanf(sfile,"\n%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&pass,&seat,&flight);
if(strcmp(Target,name)==0)
{
Found=1;
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);



fprintf(temp,"\n%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,seat,flight);
}
else
{
fprintf(temp,"\n%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,seat,flight);
}
}
if(Found==1)
printf("\n\tRedord has been changed\n");
else
printf("\nRecord not found\n");
fclose(sfile);
fclose(temp);
remove("c:\\air.txt");
rename("c:\\temp.txt","c:\\air.txt");
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 pass[8];
FILE*sfile;


clrscr();

if((sfile=fopen("c:\\air.txt","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,&pass,&seat,&flight);
if(feof(sfile))
break;

printf("%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,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();

}

/*------------------------Search
reservation---------------------------------*/

void search(void)
{
char name[40],Target[40];
int res_num,Found=0;
int seat,up;
char flight[6];
char pass[8];
FILE*sfile;

if((sfile=fopen("c:\\air.txt","r"))==NULL)
printf("File Empty");

else
{
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n\tEnter Name to search: ");
fflush(stdin);
gets(Target);
while(!feof(sfile)&& Found==0)
{
fscanf(sfile,"%i\t %s \t\t%s \t%i \t%s
",&res_num,&name,&pass,&seat,
&flight);
if(strcmp(Target,name)==0)
Found=1;
}
if(Found)
{
printf("\n\nNo : %04i\n",res_num);
printf("Name : %s\n",name);
printf("NIRC no : %s\n",pass);
printf("Number of seats: %i\n",seat);
printf("Flight : %s\n",flight);

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


reserv();
}

/*--------------------------Delete
reservation--------------------------------*/

void del(void)
{
char name[40],Target[40];
int res_num,Found=0;
int seat,up;
char flight[6];
char pass[8];
FILE*sfile, *temp;

temp=fopen("c:\\temp.txt","w");
if((sfile=fopen("c:\\air.txt","r"))==NULL)
printf("File Empty!");

else
{
clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n\n\tEnter name to delete: ");
fflush(stdin);
gets(Target);
while(!feof(sfile))
{
fscanf(sfile,"%04i \t%s \t\t%s \t%i \t
%s",&res_num,&name,&pass,&seat,&flight);
if(feof(sfile))
break;
if(strcmp(Target,name)!=0)
fprintf(temp,"%04i \t%s \t\t%s \t%i \t%s
\n",res_num,name,pass,seat,flight);
else
{
Found=1;
printf("\n\nNo : %04i\n",res_num);
printf("Name : %s\n",name);
printf("NIRC no : %s\n",pass);
printf("Number of seats: %i\n",seat);
printf("Flight : %s\n",flight);
}
}
if(!Found)
printf("Record not found");
}
printf("\nRecord deleted.");
fclose(sfile);
fclose(temp);
remove("c:\\air.txt");
rename("c:\\temp.txt","c:\\air.txt");

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


reserv();

}


/*-------------------------Flight
List----------------------------------------*/

void fly(void)
{
int choice3;

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

gotoxy(10,10);
printf("1. Add flight\n");
gotoxy(10,12);
printf("2. Flight List\n");
gotoxy(10,14);
printf("3. Exit\n");
printf("\n\n\n");
gotoxy(10,18);
printf("\tEnter your choice[1-3]: ");
scanf("%i",&choice3);
printf("\n");


switch(choice3)
{
case 1:
flyadd(); /*--------Add flight---------*/

break;

case 2:
viewfly(); /*---------Flight list--------*/
break;

case 3:
menu(); /*-----go back to main menu-----*/
break;

default:
printf("\t\tInvalid Entry!\n");
printf("\t\tEnter your choice[1-3]: ");
scanf("%i",&choice3);
getch();
}
}



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

void flyadd(void)
{
char flight_no[40];
int num=0;
int num_seat,up;

char des[40];
float price;

FILE*supfile;

if((supfile=fopen("c:\\flight.txt","a+"))==NULL)
num=1;

else
{
do{
fscanf(supfile,"%i %s %i %f %s ",&num,&flight_no,&num_seat,&price,
&des);

}while(!feof(supfile));
num+=1;

}


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

printf("No: %i ",num);
printf("\nFlight No : ");
fflush(stdin);
gets(flight_no);
printf("seats available : ");
scanf("%i",&num_seat);
printf("Price : ");
scanf("%f",&price);

printf("Destination : ");
fflush(stdin);
gets(des);


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

fprintf(supfile,"%i %s %i %.2f %s
\n",num,flight_no,num_seat,price,des);
fclose(supfile);
do{
printf("\nPress [2] to go to flight menue: ");
scanf("%i",&up);
if(up!=2)
printf("Invalid Entry");
}while(up!=2);


fly();

}

/*----------------------------View Flight
Details-----------------------------*/

void viewfly(void)
{
char flight_no[40];
int num=0;
int num_seat,up;
char des[40];
float price;

FILE*supfile;


clrscr();

if((supfile=fopen("c:\\flight.txt","a+"))==NULL)
printf("File Empty!");

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

while(!feof(supfile))
{
fscanf(supfile,"%i \t %s \t %i \t%f %s
",&num,&flight_no,&num_seat,&price,
&des);
if(feof(supfile))
break;

printf("%i \t %s \t %i \t%.2f %s
\n",num,flight_no,num_seat,price,des);
}
}

fclose(supfile);

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


fly();

}

/*--------------------------------Help-------------------------------
*/

void help(void)

{
int up;

clrscr();
gotoxy(5,3);
printf("\t\t ASIAN RAFFAYA AIRLINE RESERVATION\n");
printf("\t\t ----------------------------------\n");
printf("\n");
printf("\t\t Help\n");
printf("\t\t --------\n\n");
printf("\n\nThis module provides some fundamental helps for the
user.. ");
printf("\nMain menu shows all the obtainable functions like
RESERVATION, FLIGHT LIST.\n");
printf("Reservation screen helps to add,edit,view,search and delete
reservations.\n");
printf("Flight Menu allow to add and display details about flights
available.\n");

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

menu();
}


/*--------------------------------
Exit---------------------------------------*/
void exit(void)
{
clrscr();
gotoxy(23,10);
printf(" THANK YOU");
gotoxy(23,13);
printf("**** Enjoy your trip ****");

}
 
S

santosh

Amali said:
I submited my project and its working. I haven't done many things in
the class so i have to do my project accoding to the text book. but
these days i'm studing more about c programming. Please tell me some
links to get tutorial in c programming. Anyway i'll send you my
codings. Thank you.

<snip mess>

You really are incapable of learning, aren't you? You don't seem to
have corrected any of the discrepancies pointed out to you earlier.
Maybe you should consider giving a rest to programming?
 
R

Richard Bos

Amali said:
I submited my project and its working. I haven't done many things in
the class so i have to do my project accoding to the text book. but
these days i'm studing more about c programming. Please tell me some
links to get tutorial in c programming. Anyway i'll send you my
codings. Thank you.

Does your teacher know what he's doing? If so:
void main(void)

Automatic fail.

Richard
 
A

Amali

<snip mess>

You really are incapable of learning, aren't you? You don't seem to
have corrected any of the discrepancies pointed out to you earlier.
Maybe you should consider giving a rest to programming?- Hide quoted text -

- Show quoted text -

I got what they pointed out.but in this project they are mostly
considering about only the documentation. And it is no enought to this
project what we learnt in the class. Now i need to learn more about c
programming.
 
A

Amali

Does your teacher know what he's doing? If so:


Automatic fail.

Richard

Why it must int main. accoding to my knowladege it is not returning
any thing. Its only calling to another function.
 
R

Richard Heathfield

Amali said:
Now i need to learn more about c programming.

I posted this stuff before, but you appear to have missed it, so here we
go again.

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.
 
R

Richard Heathfield

Amali said:
Why it must int main.

Because that's the way the language is defined.
accoding to my knowladege it is not returning any thing.

It should be returning an int. Not returning anything from main is a bug
in your program - one of many.
 
S

santosh

Amali said:
Why it must int main.

Because, that's how the Standard for C says it should be declared.
accoding to my knowladege it is not returning
any thing. Its only calling to another function.

It *should* return an int value. That's one of the numerous problems
in your program. Unless you're prepared to learn when there's an
opportunity, you'll find programming very frustrating and, ultimately,
a failure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top