empty character constant problem

This is a discussion on empty character constant problem within the C++ Programming forums, part of the General Programming Boards category; Moderator note: this thread inappropriately resurrected empty character constant ?? Hey guys. sorry about jumping in on somebody elses thread, ...

  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,185
    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
    21,435
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,185
    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,185
    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, 06:54 PM
  5. c++ problem with character manipulation
    By scrapper777 in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2003, 10:48 PM

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