Thread: array of structures

  1. #1
    Registered User
    Join Date
    Dec 2003

    array of structures

    hey everyone,
    i'm writing an airline program for my c++ class, and i cant get the program to load past the array display_menu, i dont know what's going on with it
    i was wondering if someone could look at it and tell me what's going on with it,

    oh, and attarched is the "c:\felicias\airline.txt" file i made (i also pasted the code in there),
    the text file is probably wrong, i dont know..
    i was just trying to get it to work and i thought maybe that was the prob.

    here are the requirements...
    Purpose: to read and process information from a sequential file using an array of structures.

    Produce an airline reservations program to read up to 50 entries from the data file i:\techbldg\instructors\marty\airline.txt into an array of structures. Each record will contain the following fields : Flight number (integer), space, Origination point ( 15 chars), space, Destination point (15 chars), space, Departure time (8 chars), and Departure date (8 chars).

    The program should then provide a user-friendly menu screen to allow the user to:

    1. Search by Flight number
    2. Search by Origination Point
    3. Search by Destination point

    Choice 1: The program will then perform a sequential search by flight number to display the Origination point, Destination point, and Departure time.

    Choice 2 & 3: The program will do a sequential search by city name, displaying each city with the entered name.

    An error message should print if the flight number or city name is not found.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    read the faq then you should see your problems.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    Registered User
    Join Date
    Dec 2003
    but i'm not even sure what my question is

  4. #4
    Registered User
    Join Date
    May 2003
    I just looked over your program quickly and noticed a few things.

    > void main ()
    main always returns an int

    > f=fopen("c:\\felicias\\airline.txt", "r");
    You should check the file pointer to make sure the file is opened properly

    while (! feof(f))
      fscanf(f, "%d ", & flt[x].flytno);
      fscanf(f, "\n");
    You shouldn't control your loop with feof(). Check out this faq.

    Also, you are reading more data than you should. The origin field was supposed to have 15 chars plus 1 space. You are reading 16 chars and then reading another right after.

    void input_selection(int *sel)
      cout<<"Selection? (1-4) ";
    This is the only thing I see that might be the cause of your problem. You never flush the output buffer, so your program might be waiting for input without ever displaying the prompt. In this case, it will look like the program has hung right after displaying the menu. Trying adding << flush to the end of your cout statement.

    cout<<"Enter origination point you're looking for: ";
    Same problem here. By the way, are you using C or C++? It's really not good form to mix C and C++ IO in one program. And even if you did want to use C IO, gets() is bad.

    I hope that helps.


  5. #5
    Registered User
    Join Date
    Dec 2003
    thanks so much for your help,
    i'm going to try changing your suggestions and see if that works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  2. filling an array of structures?
    By voodoo3182 in forum C Programming
    Replies: 9
    Last Post: 08-06-2005, 05:29 PM
  3. Array of Structures: Sorting
    By Drainy in forum C Programming
    Replies: 3
    Last Post: 04-13-2005, 09:55 AM
  4. Filling an Array of Structures
    By Zildjian in forum C Programming
    Replies: 5
    Last Post: 11-12-2003, 05:54 PM
  5. Need serious help on array of structures
    By cwd in forum C Programming
    Replies: 2
    Last Post: 11-11-2001, 03:39 PM