-4

I have a list of arrays, each with its own descriptive name. How can I create a pointer to a particular array just using the name (ie string) of the array?

Dirk Bruere
  • 237
  • 2
  • 15
  • 4
    It's better to use code to explain yourself. – Yu Hao Sep 24 '14 at 11:20
  • not clear what you are asking ... or do you just want the address of an array variable? This can be done with `&` as for any other variable. – Jens Gustedt Sep 24 '14 at 11:21
  • 2
    Needing to do this in any programming language is a sure sign you've designed things horribly. Why do you have a variable name in a string? – Wooble Sep 24 '14 at 11:21
  • Do the arrays all have the same type, or do they have different types? – Klas Lindbäck Sep 24 '14 at 11:26
  • All the same type of the same dimension. I will implement it as a struct containing a name string. It's at this point I wish I can done it in C++... – Dirk Bruere Sep 24 '14 at 11:36

2 Answers2

4

If I understand correctly, what you mean and what you want, then you want something as Map, Dictionary etc. For example, look at this question: Quick Way to Implement Dictionary in C

Community
  • 1
  • 1
Mike S.
  • 1,995
  • 13
  • 25
2

The C programming language is somewhat of a "low-level" language. It doesn't natively have any introspection constructs.

The names you see/use are just labels that are converted to addresses by the compiler when building a static executable, so the running code has no way to look up things by variable name.

MattBianco
  • 1,501
  • 2
  • 20
  • 30