Thread: strange problem, not sure what is wrong

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Shadow12345
    Guest

    strange problem, not sure what is wrong

    This is code that is giving me trouble:
    Code:
    int main(void) {
    const	char Off[] = "Off";
    	Sensor *X = new Sensor("On", "near the front door");
    	MainFrame *W = new MainFrame("Off");
    	
    	cout << "Sensor X is located " << X->GetLocation() << endl;
    	cout << "Sensor X is currently " << X->GetSensorState() << endl;
    The output from this code should be:
    Sensor X is located near the front door (this works)
    Sensor X is currently On

    Instead I get:
    Sensor X is located near the front door
    Sensor X is currently Onnear the front door

    This is the function GetSensorState:
    Code:
    inline	char *GetSensorState()  { return State; }
    All it does is return State which is a protected character array. State is defined as
    char State[2] (only meant to hold 'On' or 'Off' so i figured 2 is enough)

    The function GetLocation is:
    Code:
     inline	char *GetLocation()  { return itsLocation; }
    All GetLocation does is return itsLocation which is a protected character array that describes the location of the sensor
    itsLocation is defined as:
    char itsLocation[50];

    I am honestly not sure what is wrong here, this is quite strange.
    Last edited by Shadow12345; 07-21-2002 at 11:21 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange problem with GETLINE
    By wco5002 in forum C++ Programming
    Replies: 13
    Last Post: 07-07-2008, 09:57 AM
  2. Strange problem
    By G4B3 in forum C Programming
    Replies: 6
    Last Post: 05-14-2008, 02:07 PM
  3. Strange problem with classes in header files
    By samGwilliam in forum C++ Programming
    Replies: 2
    Last Post: 02-29-2008, 04:55 AM
  4. Extremely strange "delete" problem
    By dr_jaymahdi in forum C++ Programming
    Replies: 4
    Last Post: 10-21-2007, 09:06 PM
  5. strange dll relatred problem
    By cloudy in forum Windows Programming
    Replies: 6
    Last Post: 07-03-2005, 05:30 PM