#include<stdio.h>
#include<stdlib.h>
#define MAX 30
int menu(){
int choice;
printf("1. Add a new reservation\n");
printf("2. Show details of a reservation (given reservation number)\n");
printf("3. Make Payment (given the reservation number and payment amount)\n");
printf("4. Confirm a Reservation (given the reservation number)\n");
printf("5. Quit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
return(choice);
}
int GetReservationNumber(){
int PNR;
do{
printf("Enter reservation number: ");
scanf("%d", &PNR);
if(PNR < 0)
printf("Wrong number\n");
}while(PNR < 0);
return(PNR);
}
 
void DisplayInfo(char first[][15], char last[][15], int seats[], char destination[][15], float amount[], int confirmed[], int PNR){
printf("\nNAME : %s %s\n", first[PNR], last[PNR]);
printf("# SEATS : %d\n", seats[PNR]);
printf("DESTINATION: %s\n", destination[PNR]);
printf("AMOUNT : %.3f SAR\n", amount[PNR]);
if(confirmed[PNR] == 1)
printf("STATUS : CONFIRMED\n\n");
else
printf("STATUS : UNCONFIRMED\n\n");
}
void AddNew(char first[][15], char last[][15], int seats[], char destination[][15], int n){
printf("Enter first name: ");
scanf("%s", first[n]);
printf("Enter last name: ");
scanf("%s", last[n]);
do{
printf("Enter number of seats: ");
scanf("%d", &seats[n]);
if(seats[n] <= 0)
printf("Wrong number\n");
}while(seats[n] <= 0);
printf("Enter destination: ");
scanf("%s", destination[n]); 
}
void GetAmount(float amount[], int PNR){
do{
printf("Enter the amount in SAR: ");
scanf("%f", &amount[PNR]);
if(amount[PNR] <= 0)
printf("Wrong amount\n");
else
printf("Thank you\n\n");
}while(amount[PNR] <= 0);
}
main(){
int seats[MAX], confirmed[MAX], n, reserved[MAX], i, PNR, choice;
float amount[MAX];
char first[MAX][15], last[MAX][15], destination[MAX][15];
FILE *inp, *outp;
inp = fopen("E:reservat.txt", "r");
if(inp == NULL){
printf("Cannot open the file ");
exit(1);
}
for(i = 0; i < MAX; i++)
reserved[i] = 0;
n = 0;
for(int status = fscanf(inp, "%s", first[n]);
status != EOF;
status = fscanf(inp, "%s", first[n])){
fscanf(inp, "%s%d%s%f%d", last[n], &seats[n], destination[n], &amount[n], &confirmed[n]);
reserved[n] = 1;
n++;
}
fclose(inp);
do{
choice = menu();
switch(choice){
case 1: if(n < MAX){
AddNew(first, last, seats, destination, n);
reserved[n] = 1;
printf("Thank You, your reservation number is %d (Unconfirmed)\n\n", n);
n++;
}else
printf("The arrays are full\n\n");
break;
case 2: PNR = GetReservationNumber();
if(reserved[PNR] == 1)
DisplayInfo(first, last, seats, destination, amount, confirmed, PNR);
else
printf("Not Found\n\n");
break;
case 3: PNR = GetReservationNumber();
if(reserved[PNR] == 1)
GetAmount(amount, PNR);
else
printf("Not Found\n\n");
break;
case 4: PNR = GetReservationNumber();
if(reserved[PNR] == 1){
confirmed[PNR] = 1;
printf("The reservation is confirmed\n\n");
}else
printf("Not Found\n\n");
break;
case 5: outp = fopen("a:reservation.txt", "w");
for(i = 0; i < n; i++)
fprintf(outp, "%s %s %d %s %.3f %d\n", first[i], last[i], seats[i], destination[i], amount[i], confirmed[i]);
fclose(outp);
printf("Thank You..");
break;
default: printf("Wrong Choice\n\n");
}
}while(choice != 5);

im getting 2 errors in the lines:for(int status = fscanf(inp, "%s", first[n]);and status != EOF;

my program is not getting executed!!there is a problem in the lines i mentioned above.can u please rectify!!!
pria

change this

FILE *inp, *outp;
    inp = fopen("E:reservat.txt", "r");
    if(inp == NULL)
    {
        printf("Cannot open the file ");
        exit(1);
    }
    for(i = 0; i < MAX; i++)
        reserved[i] = 0;
    n = 0;
    
    for
    (
        int status = fscanf(inp, "%s", first[n]);
        status != EOF;
        status = fscanf(inp, "%s", first[n])
    )
    {

to
this

FILE *inp, *outp;
    int status;
    inp = fopen("E:reservat.txt", "r");
    if(inp == NULL)
    {
        printf("Cannot open the file ");
        exit(1);
    }
    for(i = 0; i < MAX; i++)
        reserved[i] = 0;
    n = 0;
    for
    (
        status = fscanf(inp, "%s", first[n]);
        status != EOF;
        status = fscanf(inp, "%s", first[n])
    )
    {

The reason is you can't declare variables everywhere in C like in C++. All the variables in C must be declared at the beginning of a block before any other C statements.

hey sorry to disturb you!!i have to submit my assignment 2moro!!so im lil tensed...did u trace where ive gone wrong????

hey thank you very much!but again i faced a warning at the end....which says function should return a value in the last line
while(choice != 5);

Well you could help yourself by telling us which actual error messages you see.

> am compiling it in turboc
Ah, good old stone age technology - have you sharpened the stone chisel recently?

I'm also guessing you don't know the answer to the question "are you compiling C or C++" either. Sure it looks mostly like C, but that really depends on whether you called your file prog.c or prog.cpp.
Or whether you've passed any other options to the compiler to tell it which language to assume.

> for(int status =
C only got this kind of declaration in the C99 standard, which your compiler predates by decades, so it isn't going to support it.
I don't recall when C++ allowed this either, but I'd guess your fossil compiler won't even understand this in C++ mode either.

Declare the int at the start of the block (like you do for all your other variables) and see how you get on with that.

Now get a decent compiler (one made for this millenium) and leave turbo-c to the archaeology students.
http://www.compilers.net/Dir/Free/Compilers/CCpp.htm
Borland 5.5, Dev-C++, Digital Mars, MinGW, Microsoft Visual C++ express would all be a big step forward.

Late, but nevermind....

and could u please tell me what are these linker errors!im unable to get the output.

yea am getting a warning at the end which says that function should return a value.
in the last line }
and thank you.will download the new compiler...

Linker errors - I see no linker errors.
Try and think ahead when you post, anticipate what people are going to ask in response to content-free one-line posts.

> and thank you.will download the new compiler...
I think I would save that until tomorrow. It's not a good idea to change this close to the deadline. Get it out of the way, then you'll have plenty of time to install and get used to it.

there is a warning!!could u please help me...in the last statement im getting a warning which says function should return a value????

How to ask a question about code:

  1. Learn to use indentation.
  2. Post the whole code that is your latest attempt.
  3. Use code tags.
  4. If there are error or warning messages, copy and paste them into the post.
  5. Ask the question, state what confuses you, etc.

None of your attempts yet fit that mold, so it should come as no surprise that you do not yet have an answer. Had you followed this procedure your question would probably have been answered already.

The following is an example of a useless post:

there is a warning.can u please tell me...

Try to incorporate small scripts into a bigger one only then u can trace out the codes?

This article has been dead for over six months. Start a new discussion instead.