Thread: char arrays

  1. #1

    Exclamation char arrays

    First of all - forgive the formatting of the code in this forum, but I cut/pasted from the complier straight into this forum. If anyone can give me a hand, it would be greatly appriciated. I desparately need help in working with Char array, and passing value in and out of functions. The 'putInCoach' function is not working, and needs help.


    //Lab 0
    //Airline Reservation Program
    /************************************************** *********************************/
    #include <stdio.h>
    #include <iostream.h>
    #include <string.h>
    using namespace std;

    /*************************Prototype Declarations************************************/
    void getCoachClassReservations();
    void putInCoach(char *coachClassSeat);
    /************************************************** *********************************/
    int main ()
    char selection; //varible for usr menu selection
    char coachClassSeat[30][2]; //array for last name of Coach Passenger


    cout << "*****Wheezer Airlines Reservations****"<<endl;
    cout << "* *"<<endl;
    cout << "* 1. Display all reservations *"<<endl;
    cout << "* 2. Make First Class Reservations *"<<endl;
    cout << "* 3. Make Coach Class Reservations *"<<endl;
    cout << "* 4. Exit/Logout *"<<endl;
    cout << "* *"<<endl;
    cout << "**************************************"<<endl<<en dl;
    cin >> selection;

    if(selection=!'1' || selection!='2' || selection!='3' || selection!='4')
    cout << "INVALID INPUT"<<endl;
    cout << "Please enter 1-4"<<endl;
    cin >> selection ;
    return 0;

    void putInCoach(char *coachClassSeat)
    for(int x=0; x<4; x++)
    if (&coachClassSeat[x] != 0)
    cout << "Seat is availble for Passenger wanting to fly Coach Class"<<endl;
    cout << "Enter Passenger Last Name"<<endl;
    cin >> coachClassSeat[0];
    cout << "ALL SEATS ARE TAKEN"<<endl;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > char coachClassSeat[30][2]; //array for last name of Coach Passenger
    What exactly are you storing in this array?
    As it stands, you have 30 strings, with a maximum of length of 1 character ([2] allows for a single char, and a \0).

    > void putInCoach(char *coachClassSeat);
    The correct prototype for the given array would be
    void putInCoach( char coachClassSeat[30][2] );
    See how it matches the array declaration.

    There are other ways of writing it, but this way is easiest to see.

    > putInCoach(&coachClassSeat[30][2]);
    The call is dead easy
    putInCoach( coachClassSeat );

    > for(int x=0; x<4; x++)
    Woah, where did that 4 come from?

  3. #3
    what is the world comming to when someone sees a character array and assumes it is a string?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  2. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  3. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM