Thread: empty character constant problem

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    Post empty character constant problem

    Moderator note: this thread inappropriately resurrected empty character constant ??

    Hey guys. sorry about jumping in on somebody elses thread, but my problem is the same.

    I had an empty character constant problem, but I really dont know what the fill the ' ' empty space with.
    Ive taken a screen shot of a portion of the code, if it would help you to help me I can of course upload the code so you can see it all.

    http://i15.photobucket.com/albums/a3...il/Capture.jpg

    http://i15.photobucket.com/albums/a3...il/Capture.jpg
    Last edited by laserlight; 04-14-2010 at 10:30 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't see an empty character constant in the code (do you have a line number to go with it).

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    I think I have displeased the gods in resurecting this thread. Should I start a new one for my problem?

    Oh sorry...
    I added a 'j' character as I was working to see if it would change.
    Adding the j produces an error when I run the app, but when I comment out the ' ' code line the same error is produced.

    Would it be better if a posted the whole code so you would better able to help me.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ElectroSoldier
    Would it be better if a posted the whole code so you would better able to help me.
    Probably. Please post it well indented in [code][/code] bbcode tags, and do not start a new thread for this.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So you have to figure out what you want to print. If you want to print a blank space, then that's what you should print:
    Code:
    ' '
    as opposed to
    Code:
    ''
    The crash is unrelated to this and is based on you doing something wrong somewhere else.

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    Ok, I just changed it from '' to ' ' and your right the error is the same.
    The code is 128 lines long, I cant see if there is a limit on here as to how long the code can be, so I hope its not against the rules.

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    
    class rectangle
    {
          public:
                 rectangle();
                 void set_ht(int);
                 void set_wth(int);
                 void set_col(int);
                 void make_rect(); //instance of rectangle with values H, W & C
                 
                 int get_ht();
                 int get_wth();
                 int get_col();
                 
                 int calc_area();
                 
                 private:
                         int height;
                         int width;
                         int colour;
                         int area;
    };
    
    rectangle::rectangle() //constructor
    {
                           height=0;
                           width=0;
                           colour=0;
                           area=0;
    }
    
    void rectangle::set_ht(int h)
    {
         height=h;
    }
    
    void rectangle::set_wth(int w)
    {
         width=w;
    }
    
    void rectangle::set_col(int c)
    {
         colour=c;
    }
    
    int rectangle::get_ht()
    {
        return height;
    }
    
    int rectangle::get_wth()
    {
        return width;
    }
    
    int rectangle::get_col()
    {
        return colour;
    }
    
    void rectangle::make_rect() //int height, int width, int colour)
    {
         //code for colour
         HANDLE hConsole;
         hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
         SetConsoleTextAttribute(hConsole, colour);
         
         cout<<endl;
         //draw top line and corners
         cout<< (char)0xDa; //corner
         for(int i=0; i<width; ++i)
         cout<<(char)0xC4; //horizontal line
         cout<<(char)0xBF; //corner
         cout<<endl;
         
    // vertical edges
    for(int i=0; i<height; ++i) //height of rectangle
    {
            cout<<(char)0xB3; //vertical line
            for(int j=0; j<width; ++j)
            cout<< ' ';
            cout<<(char)0xB3;
            cout<<endl;
    }
    
    //Bottom line and corners
    cout<<(char)0xC0; //corner
    for(int i=0; i<width; ++i)
    cout<<(char)0xC4; //Horizontal line
    cout<<(char)0xD9; //corner
    cout<<endl;
    }
    
    //MAIN
    
    int rectangle::calc_area()
    {
        area=width*height;
        return area;
    }
    
    int main(int argc, char *argv[])
    {
        rectangle x;
        
        int ht, wd, cl, a;
        cout<< "Enter height" << endl;
        cin>>ht;
        x.set_wth(wd);
        
        cout<< "Enter colour 0 to 15" << endl;
        cin>>cl;
        x.set_col(cl);
        
        x.make_rect();
        a=x.calc_area();
        cout<<"ractangle area is " <<a<<endl;
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Thats my code, as you can see its nothing special, im only in my first year.
    The error is it continiously produces a colured line in an endless loop... line after line after line.
    Can you see what Ive done wrong, my eyes are going square looking ((

    I intend to make the class into a haeder and then run it from main by sinply including the header and then the data capture as you can see, thats why main is at the bottom... can I do it like that?
    Last edited by ElectroSoldier; 04-14-2010 at 11:02 AM.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You read in ht, and then proceed to set_wth(wd), where wd has garbage value.

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    I see. I got it now, thank you ))
    O.U.1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Character problem
    By Guru_ in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2009, 06:12 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. Comparing Character Arrays problem...
    By newy100 in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2003, 07:54 PM
  5. c++ problem with character manipulation
    By scrapper777 in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2003, 11:48 PM