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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:10:21+00:00 2026-05-20T21:10:21+00:00

I think what I am looking for is actually not possible in C, but

  • 0

I think what I am looking for is actually not possible in C, but maybe some has an idea how to work around it:

I need to process some input data. This data is given in an int with gives the number of data and a number of strings (i.e. char *) which hold the actual data. These strings are named data_0 … data_n:

 int n = 42; // the number of strings
 char *data_0 = "some input1";
 char *data_1 = "some input2";
 ....
 char *data_41 = "the last input data";

So this is how I get the data. The question now is: How can I process it? My goal is to store them in a big array. Initializing this array is of course simple, I just need an array of n char-Pointer which I get with malloc.
But then I want to assign these strings into the array. And this is the point where I’m stuck. I need to assign them dynamically, as I do not know the size before.
Something like:

 for(i = 0; i < n; i++)
      datastorage[i] = data_i;

So I mean accessing the variablename dynamically. I hope you understand what I mean 🙂 Thank you.

  • 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-20T21:10:21+00:00Added an answer on May 20, 2026 at 9:10 pm

    Make it an array in the first place! There is absolutely no point in having 42 separate variables if you have to access them as an array! BTW, in C, variable names are not available at run time, they are simply lost after compilation, so forget about dynamically accessing variables by name.

    int n = 42; // the number of strings
    char *data[42];
          data[0] = "some input1";
          data[1] = "some input2";
    ....
          data[41] = "the last input data";
    
    for(i = 0; i < n; i++)
        datastorage[i] = data[i];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After looking at several questions/answers here, I'm not seeing what I think I need.
Really quick here... I think I have the answer, but just looking for some
I've tried Key.Subtract but I think that is the numpad version. I'm looking for
I'm writing an windforms application using .NET (actually IronPython, but that's not relevant), and
I need to process an input file, and copy its content (line by ilne)
At work I use ClearCase and SourceSafe, but have found some time to do
Please ignore whether a pattern like this is actually a good idea or not.
Looking at the related questions, I don't think this specific question has been asked,
I think that looking at others' code is a good way to learn. I'm
I think this is easily explained by looking at code, so I'm posting a

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.