I'm looking for a way to get a char* from a user and using this string to refer to a variable in my program.
This resembles the pre processesor's paste option ##
.
For example say I have a function:
f(int num);
And variables
int x = 1, z = 2;
And I want to be able to do something like the following:
int y=f(##arg [1]); \\should be equivalent to: int y=f(x) assuming argv[1] ="x"
Or if the input is "z" then send z to f()...
Is there some way this can be achieved?
Thanks.
Edit: The solution doesn't have to be perfectly dynamic, I can live with some assumptions, like making the available variables strict, i.e only have a set of allowed variable names.