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 8963449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:21:30+00:00 2026-06-15T16:21:30+00:00

The issue that I am having is that I am trying to build a

  • 0

The issue that I am having is that I am trying to build a DLL. And I am using char instead of strings to store information.

I have defined the following in the header file:

class Test{
public:
    int qLenght;
    char firstName[];
    char surName[];
};

I am having problems inputting codes from the main program using the following:

int main()
{

        Test theTest;
        theTest.firstName[0] = {"Mike Smith","Jonny Vegas","Jimmy Woo"};

}

I have included the header code at the top of my main project.

It won’t let me add to the char array. This may seem like a stupid question but I am struggling and hopefully someone can shed some light as to where I am going wrong. Am I missing a parameter?

  • 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-06-15T16:21:31+00:00Added an answer on June 15, 2026 at 4:21 pm

    Your class needs to know how much memory to allocate when you instantiate the class (which is not the same time as you assign the values).

    class Test
    {
    public:
        char firstName[2][100];
    };
    
    int main()
    {
        Test theTest;
        strcpy(theTest.firstName[0], "Mike Smith");
        strcpy(theTest.firstName[1], "Jonny Vegas");
        return 0;
    }
    

    Alternatively, you can allocate memory for the strings dynamically at the time of assignment, but then you need to remember to free it again:

    class Test{
    public:
        char *firstName[2];
    };
    
    int main()
    {
        Test theTest;
        theTest.firstName[0] = strdup("Mike Smith");
        theTest.firstName[1] = strdup("Jonny Vegas");
    
        // do stuff
    
        free(theTest.firstName[0]);
        free(theTest.firstName[1]);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue where I have a player object that I'm trying to
I'm having an issue trying to build a JSONArray in android that has more
I am having an issue when trying to build an Annotated Timeline Graph using
I'm having an issue with mongoid any_of . I'm trying to find objects that
I'm trying to build a CSS-based table that will be populated with information coming
G'day guys, trying to build a small invoicing system (that can generate PDF's using
Trying to build a Metro app using Javascript and having issues with IndexedDb. I
I'm having an issue when trying to export the release build of my AIR
I having issue that content assistant / intellisense is working in methods such as
I am having an issue that I can't seem to figure out. Hopefully somebody

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.