Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 883005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:30:58+00:00 2026-05-15T12:30:58+00:00

Basically, I’m passing a pointer to a character string into my constructor, which in

  • 0

Basically, I’m passing a pointer to a character string into my constructor, which in turn initializes its base constructor when passing the string value in. For some reason strlen() is not working, so it does not go into the right if statement. I have checked to make sure that there is a value in the variable and there is.

Here is my code, I’ve taken out all the irrelevant parts:

Label class contents:

Label(int row, int column, const char *s, int length = 0) : LField(row, column, length, s, false)
{
}

Label (const Label &obj) : LField(obj)\
{
}

~Label()
{
}

Field *clone() const
{
    return new Label(*this);
}

LField class contents:

LField(int rowNumVal, int colNumVal, int widthVal, const char *valVal = "", bool canEditVal = true)
{ 
    if(strlen(valVal) > 0)
    {
    }
    else
    {
        //This is where it jumps to, even though the value in
        //valVal is 'SFields:'
        val = NULL;
    }
}

Field *clone() const
{
    return new LField(*this);
}

LField(const LField &clone) { 
    delete[] val;
    val = new char[strlen(clone.val) + 1]; 
    strcpy(val, clone.val);
    rowNum = clone.rowNum;
    colNum = clone.colNum;
    width = clone.width;
    canEdit = clone.canEdit;
    index = clone.index;
}

Screen class contents:

class Screen {
    Field *fields[50];
    int numOfFields;
    int currentField;
public:
    Screen()
    {
        numOfFields = 0;
        currentField = 0;
        for(int i = 0; i < 50; i++)
        fields[i] = NULL;
    }


    ~Screen()
    { 
        for (int i = 0; i < 50; i++)
            delete[] fields[i]; 
    }

    int add(const Field &obj)
    {
        int returnVal = 0;
        if (currentField < 50)
        {
            delete[] fields[currentField];
            fields[currentField] = obj.clone();   
            numOfFields += 1;   
            currentField += 1;      
            returnVal = numOfFields;    
        }
        return returnVal;
    }

    Screen& operator+=(const Field &obj)
    {
        int temp = 0;
        temp = add(obj);
        return *this;
    }
};

Main:

int main () {
    Screen s1;
    s1 += Label(3, 3, "SFields:");
}

Hopefully someone is able to see if I am doing something wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:30:58+00:00Added an answer on May 15, 2026 at 12:30 pm

    Marcin at this point the problem will come down to debugging, I copied your code with some minor omissions and got the correct result.

    Now it needs to be said, you should be using more C++ idiomatic code. For instance you should be using std::string instead of const char* and std::vector instead of your raw arrays.

    Here is an example of what the LField constructor would look like with std::string:

    #include <string> // header for string
    
      LField(int rowNumVal, 
             int colNumVal, 
             int widthVal, 
             const std::string& valVal = "", 
             bool canEditVal = true)
      {
        std::cout << valVal;
          if(valVal.length() > 0)
          {
          }
          else
          {
              //This is where it jumps to, even though the value in
              //valVal is 'SFields:'
              //val = NULL;
          }
      }
    

    Using these types will make your life considerably easier and if you make the change it may just fix your problem too.

    PREVIOUS:
    So you can be CERTAIN that the string is not being passed in correctly add a printline just before the strlen call. Once you do this work backward with printlines until you find where the string is not being set. This is a basic debugging technique.

    Label(int row, 
                int column, 
                const char *s, 
                int length = 0) : 
                    LField(row, column, length, s, false) {
      }
    
        LField(int rowNumVal, 
                         int colNumVal, 
                         int widthVal, 
                         const char *valVal = "", 
                         bool canEditVal = true) 
            { 
                std::cout << valVal << std::endl;
                if(strlen(valVal) > 0) 
                {
    
                }
                else {
                                //This is where it jumps to, even though the value in
                                                                        //valVal is 'SFields:'
                    val = NULL;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have a JTextPane to hold some text which I wish to style.
Basically I have some sort of third party software running on Windows 7 which
Basically I have converted a tab delimited txt file into a list containing a
Basically this function is meant to store the height value of the element that
Basically i'd like to allow an arbitrary (but not empty ) number of key-value
Basically my question is, if I have a number string, and i'm going to
Basically I have some simple code that does some things for files and I'm
Basically we've noticed that on some computers setting the JVM option -Xmx (max heap
Basically in my in my aspx page I have a gridview which displays the
Basically, I'm using python to print out some information in the terminal and some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.