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

  • Home
  • SEARCH
  • 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 6374263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:27:58+00:00 2026-05-25T01:27:58+00:00

This is popular question so I already checked the similar threads but still didnt

  • 0

This is “popular” question so I already checked the similar threads but still didnt resolve my issue.

How can I declare 2-D array to hold “strings” – I need array of array of chars AFAIK – and use it as argument to 5 functions one after another where I can pass it by reference and update the content dynamically so following function can compare it. (I might get 10 “strings” or even empty array, so I want to do it correctly with dynamic array coz array content is different from system to system).

“string” => C style string aka array of chars. MAXLEN < 32;

C solution would be more disirable but if vectors can work, why not.

  • 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-25T01:27:58+00:00Added an answer on May 25, 2026 at 1:27 am

    One possible solution in C is as follows:

    char **p_strings = calloc(num_strings, sizeof(*p_strings));
    
    for (i = 0; i < num_strings; i++)
    {
        // Allocate storage for the i-th string (always leave room for '\0')
        p_strings[i] = calloc(len_string[i]+1, sizeof(*p_strings[i]));
    }
    
    
    ...
    
    // Call a function
    my_function(p_strings, num_strings);
    

    You will need to remember to free all this data when you’re done with it.

    If you need to alter the length of a string, or change the number of strings, you will have to do some fairly painful reallocation. So if you’re working in C++, you should probably just be using a std::vector<std::string>.

    std::vector<std::string> strings;
    
    strings.push_back("Foo");
    strings.push_back("Bar");
    
    ...
    
    my_function(strings);
    

    You can even get const pointers to C-style strings for each element, using c_str().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this question already, but I didnt see an answer.. So I get
I know this question is overly popular, but I find nothing that addresses rewriting
I recognise this is a popular question but I couldn't find anything that answered
This question is quite popular, and there are already lot of questions pertaining to
This seems to be a popular question on this site but previous answers haven't
This is similar to this question . I asked Why? to the most popular
This is a popular interview question and the only article I can find on
This popular Stack Overflow question explained why CSS selectors are parsed right to left.
I have this quite popular problem, but have failed to find a solution that
Depending on your interpretation this may or may not be a rhetorical question, but

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.