I have a slight problem because I'm not necessary combining "number" and "4" together. I'm actually combining "number" and "digit1" together, where digit1 is equal to 4.
When I try the MASHUP specified above, it gives me "numberdigit1" not "number4".
I'm trying to find values in the correct array based on some inputs. For example, if I get 4 for digit1, then I need to pull values from an array called "number4". Surely there must be a way to concatenate these two things.
There is a way to do what you want, but it's not simple. I suspect there is an easier way to accomplish your goal.
However, if you insist on doing that, here's how it could be done:
Declare your arrays.
Define a structure that holds a string pointer and a pointer to an array.
Declare an array of those structures, and initialize it with names and pointers.
Write a function that, given a name and a number, creates a string from those two, searches the array of structures, and returns the corresponding array pointer.
For example:
int array1[10];
int array2[10];
int array3[10];
struct array_entry
{
char *array_name;
int *array_ptr;
};
struct array_entry arrays[] =
{
{"number1",array1},
{"number2",array2},
{"number3",array3}
};
const int num_arrays = sizeof(arrays) / sizeof(struct array_entry);
The remainder is left as an exercise for the reader.