473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Please help me to find the error

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<memory.h>
#include<iostream.h>

void reserv(), add(), view();

void main()
{
short 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()
{
short 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()
{
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();
}

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

Oct 30 '07 #1
3 1825
On Oct 30, 2:59 pm, Alami <al...@mymail.comwrote:
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>
not a standard C header
#include<memory.h>
You want stdlib.h, no doubt
#include<iostream.h>
If it were correct, this header would make it a C++ file, and not a C
file.
Of course, that would mean instead:
#include <iostream>
However, since you are not using a single feature of iostream, there
is not any need to include it anyway.
>
void reserv(), add(), view();

void main()
in both C and C++, main returns int, not void.
{
short choice1;

clrscr();
gotoxy(5,5);
From the C-FAQ:
19.4: How can I clear the screen?
How can I print text in color?
How can I move the cursor to a specific x, y position?

A: Such things depend on the terminal type (or display) you're
using. You will have to use a library such as termcap,
terminfo, or curses, or some system-specific routines, to
perform these operations. On MS-DOS systems, two functions
to look for are clrscr() and gotoxy().

For clearing the screen, a halfway portable solution is to
print
a form-feed character ('\f'), which will cause some displays
to
clear. Even more portable (albeit even more gunky) might be
to
print enough newlines to scroll everything away. As a last
resort, you could use system() (see question 19.27) to invoke
an operating system clear-screen command.

References: PCS Sec. 5.1.4 pp. 54-60, Sec. 5.1.5 pp. 60-62.
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);
You should always check the return of scanf().
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()
{
short 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()
{
Did you know that when a function returns, automatic variables are
lost?
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));
12.2: Why does the code

while(!feof(infp)) {
fgets(buf, MAXLINE, infp);
fputs(buf, outfp);
}

copy the last line twice?

A: In C, end-of-file is only indicated *after* an input routine
has
tried to read, and failed. (In other words, C's I/O is not
like
Pascal's.) Usually, you should just check the return value of
the input routine (in this case, fgets() will return NULL on
end-
of-file); often, you don't need to use feof() at all.

References: K&R2 Sec. 7.6 p. 164; ISO Sec. 7.9.3, Sec.
7.9.7.1,
Sec. 7.9.10.2; H&S Sec. 15.14 p. 382.
Also, fscanf() with a format specifier of %s is just as bad as gets().
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);
>From the C-FAQ:
12.23: Why does everyone say not to use gets()?

A: Unlike fgets(), gets() cannot be told the size of the buffer
it's to read into, so it cannot be prevented from overflowing
that buffer. As a general rule, always use fgets(). See
question 7.1 for a code fragment illustrating the replacement
of
gets() with fgets().

References: Rationale Sec. 4.9.7.2; H&S Sec. 15.7 p. 356.
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)
{
Did you know that when a function returns, automatic variables are
lost?
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();

}

I think my problem is in add and view functions.
Please help me.
There is a long way to go with this project.

This might be a helpful start:

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*
From:
http://home.att.net/~jackklein/ctips01.html#safe_gets
*/
char *getsafe(char *buffer, int count)
{
char *result = buffer,
*np;
if ((buffer == NULL) || (count < 1))
result = NULL;
else if (count == 1)
*result = '\0';
else if ((result = fgets(buffer, count, stdin)) != NULL)
if (np = strchr(buffer, '\n'))
*np = '\0';
return result;
}

void reserv(void), add(void), view(void);

static const char *nl = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
#define gotoxy(x,y)
#define clrscr() puts(nl),puts(nl)

static char name[256];
static int res_num,
up;
static int seat;
static char flight[256];
static char pass[256];
static FILE *sfile;
Oct 30 '07 #2
Alami wrote:
>
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<memory.h>
#include<iostream.h>
The last three of these files do not exist in standard C
>
void reserv(), add(), view();

void main()
This is illegal, main returns an int. Say and do so.

This newsgroup deals in the C language, as defined in the various C
standards (present and past). Things that are not defined in those
are off-topic. Similarly C++ things are off-topic (I suspect the
<iostream.h>). Please correct these things before posting code
here. There probably are more non-standardisms to correct, I
stopped reading.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Oct 30 '07 #3
Alami wrote:
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>

Did you not post this same program months ago, at least twice IIRC? Why
don't you redesign and rewrite the program?

Oct 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: TeknoCat | last post by:
Hey everyone, I may be repeating myself here, but if someone sent a reply then I missed it, and I can't get Outlook Express to download any messages more than 2 days old. Anyway, I'm having a...
2
by: John | last post by:
This message is popping up at startup and its saying "fatal execution engine error (0x7927e03e)" Ive tried deleting, reinstalling frameworks, restoring computer, but I can't use the os cd because i...
6
by: Daniel Rimmelzwaan | last post by:
I want to send a biztalk document to an aspx page, and I need to see some sample code, because I just can't make it work. I have a port with transport type HTTP, pointing to my aspx page, something...
1
by: news | last post by:
Hi, I have just deployed my private assembly in the bin directory of my ISP and I am getting the following error. I am pretty sure it is able to find my assemblyPLEASE tell me how can I find...
3
by: Justin | last post by:
I am trying to do a simple update of a single row with the dataset below but I keep getting this error: "System.NullReferenceException: Object reference not set to an instance of an object." ...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
10
by: Rob Dob | last post by:
Hi, I'm amazed!!! I am using VS2005, I create a new web project, c# and then within the default.aspx form right mouse click and select "View Compnent Designer" , I then select and drag a...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
7
by: rn5a | last post by:
This is the second time I am asking this question in this newsgroup since I haven't got a solution or response from anyone in my previous post & I need to resolve this issue desperately. Sorry for...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.