Flight program not outputting

This is a discussion on Flight program not outputting within the C++ Programming forums, part of the General Programming Boards category; Code: Code: #include <iostream> using namespace std; #include "Flight.h" Flight::Flight(){ num = 0; dest[0] = '

Thread: Flight program not outputting

'; } Flight::Flight(int n, const ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    118

    Flight program not outputting

    Code:
    Code:
     #include <iostream>
     using namespace std;
     #include "Flight.h"
    
     Flight::Flight(){
         num = 0;
         dest[0] = '\0';
     }
     
     Flight::Flight(int n, const char* d){
         if((n>-1) && (strcmp(d,'\0') == 1)){
                   num = n;
                   strcpy(dest,d);          
         }  
         else{
                   num = 0;
                   dest[0] = '\0' ;   
         }                 
     }
     
     Flight::~Flight(){
                       
     }
     
     Flight& Flight::width(int w){
         cout.width(w);
         cout << num << dest <<endl; 
         return *this;     
     }
     
     int Flight::number() const{
         return num;    
     }
     
     const char* Flight::destination() const{
         return dest;      
     }
     
     ostream& operator<<(ostream& os, const Flight& st){
         os << st.num << ' ' << st.dest << endl;
         return os;         
     }
     
     void display(Flight flight) {
    
         cout << flight.width(2) << endl;
    
     }
    
     int main ( ) {
         Flight f, g(857, "Toronto"); 
    
         cout << g.width(9) << endl;
         f = g;
         display(f);
         cout << f.number() << endl;
         cout << f.destination() << endl;
         return 0;
     }
    Header:
    Code:
    class Flight{
                 int num;
                 char dest[15]; 
          public:
                 Flight();
                 Flight(int n, const char* d);
                 ~Flight();
                 const char* destination() const;
                 int number() const;
                 Flight& width(int); 
                 friend ostream& operator<<(ostream& os, const Flight& s);  
    };
    I dont know what the problem is, but when i run this compiled it doesnt give any output.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    '\0' is not a string and cannot be used in strcmp. Fortunately, "\0" is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Replies: 6
    Last Post: 03-02-2005, 01:45 AM
  4. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 09:49 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21