Thread: Functions Not Working...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147

    Functions Not Working...

    this is a simple program to store vehicles and their parts for a small 4x4 breakers yard, the parts and their corrosponding details are stored in a text file and read in when a vehicle is created. it also stores details of customers includint their orders etc.

    can sombody spot why my Get_Order_Quote() wont work, it doesnt seem to display an output when there should be a clear match in the array.

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <cstdio>
    #include <fstream>
    
    using namespace std;
    
    struct Part_Struct   //decleration of data structure for parts
    {
        int Part_ID;
        char Description[15];
        char Condition[10];
        float Guide_Price;
        int Origin_Vehicle_ID;
        bool Present;
    };
    
    struct Vehicle_Struct //decleration of data structure for vehicles
    {
        int Vehicle_ID;
        char Model[10];
        char Colour[10];
        int Mileage;
        float Purchase_Price;
        Part_Struct Parts[323];
    };
    
    struct Order_Struct  //decleration of data structure for orders
    {
        int Order_ID;
        int Customer_ID;
        int Part_ID[10];
        bool Paid;
    };
    
    struct Customer_Struct  //decleration of data structure for customers details
    {
           int Customer_ID;
           char Name[15];
           char Address[15];
           char Addresstwo[15];
           char Town[10];
           char County[10];
           char Postcode[6];
           char TelNo[12];
           Order_Struct Orders[10];
    };
    
    int Program;
    int Number_of_Vehicles = 0, Number_of_Customers = 0;
    
    Customer_Struct Customers[10]; //arrayed data structures
    Vehicle_Struct Vehicles[10];
    
    int Show_Main_Menu();    //function prototypes
    void Get_Order_Quote();
    void Input_New_Customer();
    void Check_Order_Details();
    void Look_Up_Customer();
    void Place_New_Order();
    void Enter_New_Vehicle();
    void Save_Customers();
    void Save_Vehicles();
    void Update_Master_File();
    void Fill_Customers_Array();
    void Fill_Vehicles_Array();
    void Read_in_Freelander();
    void Update_Program();
    void Load_Information();
    
    int main(int argc, char *argv[])
    {
        while(Program != 8)
        {//while 'program'
    
        Load_Information();
    
        switch (Show_Main_Menu())
        { //switch
    
    //------------------------------------------------------------------------------
        case 1:
        {//case 1
         cout << Vehicles[0].Model << endl;
    
         Get_Order_Quote();
         break;
    
        }//case 1
    //------------------------------------------------------------------------------
        case 2:
        {//case 2
         
         Place_New_Order();
         break;
         
        }//case 2
    //------------------------------------------------------------------------------
        case 3:
        {//case 3
    
        Check_Order_Details();
        break;
    
        }//case 3
    //------------------------------------------------------------------------------
    
        case 4:
        {//case 4
    
          Input_New_Customer();
          Save_Customers();
          break;
    
        }//case 4
    //------------------------------------------------------------------------------
    
       case 5:
        {//case 5
        
        cout << "Print Bills" << endl;
        Read_in_Freelander();
    
        break;
        
        }//case 5
    //------------------------------------------------------------------------------
        case 6:
        {//case 6
    
         Look_Up_Customer();
         break;
           
        }//case 6    
    //------------------------------------------------------------------------------
        case 7:
        {//case 7
        
        Enter_New_Vehicle();
        break;
        
        }//case 7
    //------------------------------------------------------------------------------
        case 8:
        {//case 7
        
        return 0;    
        break;
        
        }//case 7
    //------------------------------------------------------------------------------
    }//switch statement   
    
    }//while 'program'
    
    }//int main
    
    //XXXXXXXXXXXXXXXXXXXXXXX FUNCTIONS XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    int Show_Main_Menu()                //OK and tested!
    {
        int Main_Menu_Option;
        string buffer;
        system("cls");
        cout << " ** Main Menu **" << endl;
        cout << endl;
        cout << "Orders:   " << endl;
        cout << endl;
        cout << "1) Order Quote" << endl;
        cout << "2) New Order" << endl;
        cout << "3) Check Order Details" << endl;
        cout << endl;
        cout << endl;
        cout << "Customers: " << endl;
        cout << endl;
        cout << "4) Enter New Customer" << endl;
        cout << "6) Look Up Customer" << endl;
    
        cout << "5) Print Bills" << endl;
    
        cout << "7) Enter New Vehicle" << endl;
        cout << "8) Quit Program" << endl;
        cout << endl;
        cout << "Option : ";
    
        getline(cin,buffer,'\n'); 
        Main_Menu_Option = atoi(buffer.c_str());
    
        system("cls");
        return Main_Menu_Option;
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Input_New_Customer()    //looks OK but not tested!
    {
        system("cls");
        cout << "Enter New Customer" << endl;
        cout << endl;
    
        cout << "Name             : ";
        cin.getline(Customers[Number_of_Customers].Name,200);
    
        cout << "Address          : ";
        cin.getline(Customers[Number_of_Customers].Address,200);
    
        cout << "Address line two : ";
        cin.getline(Customers[Number_of_Customers].Addresstwo,200);
    
        cout << "Town             : ";
        cin.getline(Customers[Number_of_Customers].Town,200);
    
        cout << "County           : ";
        cin.getline(Customers[Number_of_Customers].County,200);
    
        cout << "Postcode         : ";
        cin.getline(Customers[Number_of_Customers].Postcode,200);
    
        cout << "Customer ID      : " << Number_of_Customers << endl;
    
        cout << endl;
        Number_of_Customers ++;
        system("PAUSE");
        system("cls");
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Check_Order_Details()      //Looks OK but not tested!
    {
        int Order_ID, i, x, y;
        string buffer;
    
        system("cls");
        cout << "Check Order Details" << endl;
        cout << endl;
        cout << "Enter Order ID  : ";
    
        getline(cin,buffer,'\n'); 
        Order_ID = atoi(buffer.c_str());
    
    
    
        for(i=0; i<Number_of_Customers; i++)     //loops through all customers
        {
                 for(x=0; x<10; x++)   //loops through all orders that customer has
                 {
                   if(Customers[i].Orders[x].Order_ID == Order_ID) //checks each order for a match on Order_ID
                   {//if statement
                        cout << Customers[i].Orders[x].Part_ID << endl;     //displays details of the order
                        cout << Customers[i].Orders[x].Paid << endl;
                        cout << Customers[i].Orders[x].Customer_ID << endl;
                        
                        for(y=0; y<Number_of_Customers; y++) //loops through all customers
                        {//for loop
                                
                   if(Customers[y].Customer_ID == Customers[i].Orders[x].Customer_ID) //checks for match on Customers ID
                                 {//if statement
                                     cout << Customers[y].Name << endl; //displays name of customer above
                                     }//if statement
                        }//for loop
                        
                   }//if statement
                  }//for loop x
        }//for loop i
    
        cout << endl;
        system("PAUSE");
    
    };//function
    
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    
    void Get_Order_Quote()  //OK but not tested!
    {
         int ID, Part_ID, i;
         string buffer;
         
         cout << "Order Quote" << endl;
         cout << endl;
         cout << "Input Part ID : ";
    
         getline(cin,buffer,'\n'); 
         Part_ID = atoi(buffer.c_str());
    
         for(i=0; i<Number_of_Vehicles; i++)      //loops through all vehicles catalogued
         {//for loop ID
            for(ID=0; ID<323; ID++)    //loops through parts available on vehicle
    
            { //for loop i
    
       if(Part_ID == Vehicles[i].Parts[ID].Part_ID && Vehicles[i].Parts[ID].Present == 1 )//checks for a match on the parts ID
               {//if
                   cout << Vehicles[i].Parts[ID].Part_ID << " is on Vehicle " << i << endl;
                   cout << Vehicles[i].Parts[ID].Description << " is " << Vehicles[i].Parts[ID].Guide_Price << endl;
                }//if
    
            }//for loop i
         }//for loop
    
     system("PAUSE");
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Place_New_Order()
    {//func place_new_order
    
        int Sub_Opt, Customer_ID, Part_ID;
        int x, i;
        string buffer;
        
        cout << "New Order" << endl;
        cout << endl;
        cout << "1) Create New Customer" << endl;
        cout << "2) Enter Customer ID" << endl;
        cout << endl;
        cout << "Option   : ";
    
        getline(cin,buffer,'\n'); 
        Sub_Opt = atoi(buffer.c_str());
    
        switch(Sub_Opt)
        {//switch subopt
    //------------------------------------------------------------------------------
        case 1:
        {//case 1
    
        Input_New_Customer();
        Save_Customers();
        break;
    
        }//case 1
    //------------------------------------------------------------------------------
        case 2:
        {//case 2
    
        cout << "Customer ID : ";
        getline(cin,buffer,'\n'); 
        Customer_ID = atoi(buffer.c_str());
    
        cout << "Enter Part ID";
        getline(cin,buffer,'\n'); 
        Part_ID = atoi(buffer.c_str());
        
        for(i=0; i<Number_of_Vehicles; i++)//loops through all vehicles
        {//for loop i
    
               for(x=0; x<323; x++)//loops through all parts in specific vehicle
               {//for loop x
    
             if(Part_ID == Vehicles[i].Parts[x].Part_ID && Vehicles[i].Parts[x].Present == 1)//test for a match of part_id and that its present on vehicle
    
                        {//if statement
    
                                   cout << Vehicles[i].Parts[x].Description << endl;
    
                                   }//if statement
                        }//for loop x
             }//for loop i
             
        break;
        }//case 2
    //------------------------------------------------------------------------------
    }//switch subopt
    };//func place_new_order
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Look_Up_Customer()        //OK and tested!
    {
            int ID;
            string buffer;
            
            cout << "Look up Customer" << endl;
            cout << endl;
            cout << "Please Enter Customer ID : ";
    
            getline(cin,buffer,'\n'); 
            ID = atoi(buffer.c_str());
    
        
                cout << "Name      : " << Customers[ID].Name << endl;
                cout << "Address   : " << Customers[ID].Address << endl;
                cout << "            " << Customers[ID].Addresstwo << endl;
                cout << "            " << Customers[ID].Town << endl;;
                cout << "            " << Customers[ID].County << endl;                   
                cout << "            " << Customers[ID].Postcode << endl;
                cout << "Telephone : " << Customers[ID].TelNo << endl;
                system("PAUSE");
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Enter_New_Vehicle()
    {//func Enter_New_Vehicle
          int i, Part_ID;
          string buffer;
          
          cout << "Enter New Vehicle For Breaking" << endl;
          cout << endl;
          cout << "Model          : ";
          cin.getline(Vehicles[Number_of_Vehicles].Model,200);
    
          cout << "Colour         : ";
          cin.getline(Vehicles[Number_of_Vehicles].Colour,200);
    
          cout << "Mileage        : ";
          getline(cin,buffer,'\n'); 
          Vehicles[Number_of_Vehicles].Mileage = atoi(buffer.c_str());
    
          cout << "Purchase Price : ";
          getline(cin,buffer,'\n'); 
          Vehicles[Number_of_Vehicles].Purchase_Price = atoi(buffer.c_str());
    
          cout << "Vehicle ID     : " << Number_of_Vehicles << endl;
    //------------------------------------------------------------------------------      
          Read_in_Freelander();
    //------------------------------------------------------------------------------
         cout << "What Parts Are Missing or Damaged?" << endl;
         cout << endl;
         cout << "Enter 8 When Finished" << endl;
         cout << endl;
         cout << "Part ID('s) Which are Missing or Damaged : ";
         getline(cin,buffer,'\n'); 
        Part_ID = atoi(buffer.c_str());
         
         if(Part_ID != 8)
         {//if statment 
                    
         for(i=0; i<323; i++)
         {//for loop
         if(Vehicles[Number_of_Vehicles].Parts[i].Part_ID == Part_ID)
         {//if statment
            Vehicles[Number_of_Vehicles].Parts[i].Present == 0;
            }//if statement
            }//for loop
         }//if statement
    
         Number_of_Vehicles++;
    
    };//func Enter_New_Vehicle
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Save_Customers()
    {
            int i, x;
            
            ofstream Customers_file ("d:\\CustomersDetails");
            
            for(i=0; i<Number_of_Customers; i++)
            {//for loop i
            Customers_file << Customers[i].Customer_ID << endl;
            Customers_file << Customers[i].Name << endl;
            Customers_file << Customers[i].Address << endl;
            Customers_file << Customers[i].Addresstwo << endl;
            Customers_file << Customers[i].Town << endl;
            Customers_file << Customers[i].County << endl;
            Customers_file << Customers[i].Postcode << endl;
            Customers_file << Customers[i].TelNo << endl;
            
            for(x=0; i<10; x++)
            {//for loop x
            Customers_file << Customers[i].Orders[x].Order_ID << endl;
            Customers_file << Customers[i].Orders[x].Customer_ID << endl;
            Customers_file << Customers[i].Orders[x].Part_ID << endl;
            Customers_file << Customers[i].Orders[x].Paid << endl;       
            }//for loopx         
            
            }//for loop i
            
            Customers_file.close();     
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Save_Vehicles()
    {
         int i,x;
         
         ofstream Vehicles_file ("d:\\VehiclesDetails");
         
         for(i=0; i<Number_of_Vehicles; i++)
         {//for loop i
          Vehicles_file << Vehicles[i].Vehicle_ID << endl;
          Vehicles_file << Vehicles[i].Model << endl;
          Vehicles_file << Vehicles[i].Colour << endl;
          Vehicles_file << Vehicles[i].Mileage << endl;
          Vehicles_file << Vehicles[i].Purchase_Price << endl;
          
          for(x=0; x<323; x++)
          {//for loop x
          Vehicles_file << Vehicles[i].Parts[x].Part_ID << endl;
          Vehicles_file << Vehicles[i].Parts[x].Description << endl;
          Vehicles_file << Vehicles[i].Parts[x].Condition << endl;
          Vehicles_file << Vehicles[i].Parts[x].Guide_Price << endl;
          Vehicles_file << Vehicles[i].Parts[x].Origin_Vehicle_ID << endl;
          Vehicles_file << Vehicles[i].Parts[x].Present << endl;
          }//for loop x
         }//for loop i
          Vehicles_file.close();
    };//funtion
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Update_Master_File()
    {
         ofstream Update_Master_file("d://MasterFile");
         
         Update_Master_file << Number_of_Customers << endl;
         Update_Master_file << Number_of_Vehicles << endl;
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Fill_Vehicles_Array()
    {
         int i,x;
         
         ifstream Vehicles_file ("d:\\VehiclesDetails");
         
         for(i=0; i<Number_of_Vehicles; i++)
         {//for loop i
          Vehicles_file >> Vehicles[i].Vehicle_ID;
          Vehicles_file >> Vehicles[i].Model;
          Vehicles_file >> Vehicles[i].Colour;
          Vehicles_file >> Vehicles[i].Mileage;
          Vehicles_file >> Vehicles[i].Purchase_Price;
          
          for(x=0; x<323; x++)
          {//for loop x
          Vehicles_file >> Vehicles[i].Parts[x].Part_ID;
          Vehicles_file >> Vehicles[i].Parts[x].Description;
          Vehicles_file >> Vehicles[i].Parts[x].Condition;
          Vehicles_file >> Vehicles[i].Parts[x].Guide_Price;
          Vehicles_file >> Vehicles[i].Parts[x].Origin_Vehicle_ID;
          Vehicles_file >> Vehicles[i].Parts[x].Present;
          }//for loop x
         }//for loop i
          Vehicles_file.close();
    };//function
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Fill_Customers_Array()
    {
            int i, x;
            
            ifstream Customers_file ("d:\\CustomersDetails");
            
            for(i=0; i<Number_of_Customers; i++)
            {//for loop i
            Customers_file >> Customers[i].Customer_ID;
            Customers_file >> Customers[i].Name;
            Customers_file >> Customers[i].Address;
            Customers_file >> Customers[i].Addresstwo;
            Customers_file >> Customers[i].Town;
            Customers_file >> Customers[i].County;
            Customers_file >> Customers[i].Postcode;
            Customers_file >> Customers[i].TelNo;
            
            for(x=0; i<10; x++)
            {//for loop x
            Customers_file >> Customers[i].Orders[x].Order_ID;
            Customers_file >> Customers[i].Orders[x].Customer_ID;
           // Customers_file >> Customers[i].Orders[x].Part_ID; //wont compile???
            Customers_file >> Customers[i].Orders[x].Paid;       
            }//for loopx         
            
            }//for loop i
            
            Customers_file.close();     
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Read_in_Freelander()
          {
          int i;
          char General_Condition[200];
    
          cout << "General Condition of Parts : ";
          cin.getline(General_Condition,200);
    
          system("PAUSE");
          ifstream FreeLanderPart;
          FreeLanderPart.open("h:\\FreeLanderPart.dat");
    
          char temp[200];
    
          for(i=0; i<323; i++)
          { //for loop i
    
         FreeLanderPart.getline(temp,5);
         Vehicles[Number_of_Vehicles].Parts[i].Part_ID = atoi(temp);  //turns temp into an integer
    
         FreeLanderPart.getline(Vehicles[Number_of_Vehicles].Parts[i].Description,40); //reads part description
    
         Vehicles[Number_of_Vehicles].Parts[i].Condition == General_Condition; //add general condition ^^
    
         FreeLanderPart.getline(temp,5);
         Vehicles[Number_of_Vehicles].Parts[i].Guide_Price = atoi(temp); //reads in guide price
    
         Vehicles[Number_of_Vehicles].Parts[i].Origin_Vehicle_ID = Number_of_Vehicles; //adds vehicle id of origin
    
         Vehicles[Number_of_Vehicles].Parts[i].Present = 1; //indicates that the part is present on the vehicle
    
    
         //cout << Vehicles[Number_of_Vehicles].Parts[i].Part_ID << endl;
         //cout << Vehicles[Number_of_Vehicles].Parts[i].Description << endl;
        //cout << Vehicles[Number_of_Vehicles].Parts[i].Guide_Price << endl;
        // Vehicles[Number_of_Vehicles].Parts[i].Condition = General_Condition;
        // FreeLanderPart >> Vehicles[Number_of_Vehicles] .Parts[i].Guide_Price;
    
          }//for loop i
          FreeLanderPart.close();
    
          system("PAUSE");
          };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Update_Program()
    {
         ifstream Update_Program("d://MasterFile");
         
         Update_Program >> Number_of_Customers;
         Update_Program >> Number_of_Vehicles;
    };
    //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    void Load_Information()
    {
        Update_Master_File();
        Fill_Customers_Array();
        Fill_Vehicles_Array();
     };
    this is an example of whats in FreeLanderParts.dat,

    1
    Abs Control Unit
    2
    Abs Ecu
    3
    Abs Modulator
    4
    Abs Pump
    5
    Abs Pump Modulator Combined
    6
    Abs Sensor
    7
    Aerial
    8
    Aerial Roof
    9
    Air Bag
    10
    Air Filter Box
    11
    Air Flow Mass Meter
    12
    Air Flow Meter
    13
    Air Mass Meter
    14
    Air Metering Unit
    15
    Airbag (roof)
    16
    Airbag (seat)


    thanks,

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Perhaps you could focus the question a little bit.

    Dumping your latest huge mess on a message board with a "fix it for me" isn't a good long term way of learning how to fix your own problems.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    Quote Originally Posted by Salem
    Perhaps you could focus the question a little bit.

    Dumping your latest huge mess on a message board with a "fix it for me" isn't a good long term way of learning how to fix your own problems.
    sos mate, i posted this when i was at school and it wouldnt let me back on to edit it.

    the Get_Order_Quote() function doest appear to work at all, neither does the Read_In_FreeLander() function. i thought it may help if you could view the entire code as it would be difficult to get them working if they were alone.

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    North Yorkshire, England
    Posts
    147
    ok, i think ive nearly sorted the Quote function, now can anybody see what could be wrong with this one, its trying to read a text file called FreeLanderPart and store it in an array. but for some reason it is't doing so.

    Code:
    void Read_in_Freelander()
          {
          int i;
          char General_Condition[200];
    
          system("PAUSE");
          ifstream FreeLanderPart;
          FreeLanderPart.open("e:\\FreeLanderPart.dat");
    
          char temp[200];
    
          for(i=0; i<323; i++)
          { //for loop i
    
         FreeLanderPart.getline(temp,5);
         Vehicles[Number_of_Vehicles].Parts[i].Part_ID = atoi(temp);  //turns temp into an integer
    
         FreeLanderPart.getline(Vehicles[Number_of_Vehicles].Parts[i].Description,40); //reads part description
    
         cout << Vehicles[Number_of_Vehicles].Parts[i].Part_ID << endl;
         cout << Vehicles[Number_of_Vehicles].Parts[i].Description << endl;
        
          }//for loop i
          FreeLanderPart.close();
    
          system("PAUSE");
          };
    thanks,

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > char Description[15];
    > FreeLanderPart.getline(Vehicles[Number_of_Vehicles].Parts[i].Description,40);
    Guess where the other 25 characters go.

    It's no use using "safe" functions if you lie about your buffer sizes.

    Rather than using lots of magic numbers, why not have something like
    const int MAX_DESC = 40;

    char Description[MAX_DESC];

    FreeLanderPart.getline(Vehicles[Number_of_Vehicles].Parts[i].Description,MAX_DESC);

    As well as being far more readable, it is also a lot less error prone.

    Using
    Code:
    FreeLanderPart.getline(Vehicles[Number_of_Vehicles].Parts[i].Description,
             sizeof Vehicles[Number_of_Vehicles].Parts[i].Description );
    Would be better, since the code would automatically adapt to changes in array size without you having to make sure you used the right constant.

    The best answer would be to use C++ std::string for everything where you have C-style char arrays.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  2. Static functions.... why?
    By patricio2626 in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2007, 08:06 PM
  3. Static member functions more efficient?
    By drrngrvy in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2006, 07:07 AM
  4. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  5. Functions are not working
    By founder247184 in forum C++ Programming
    Replies: 0
    Last Post: 11-29-2002, 04:00 PM