How doi convert/cast a c-style string's value to execute a function of the same name?
I'd prefer this question answered in C, instead of C++, if possible, but I couldn't find a proper forum. Please Help!!!
Let's say I have the following simple code:
char* szExecuteThisFunction = "foo3";
void foo1()
{
printf "Running foo1!\n"; /* that's all this guy does */
}
void foo2()
{
int i = 0; /* not much going on here either */
}
void foo3()
{
double i, j;
i = 2.0;
j = i + 10.0; /* adding 2 numbers, that's it!*/
}
The value for szExecuteThisFunction gets read in by a user, and it is basically the "name" of the function that I wish to execute. So if the value for szExecuteThisFunction = "foo1", I want it to execute the foo1() function. If it's "foo2", I want it to execute the foo2() function, etc.
My question is this: How do I make the "string" execute a "function", whose name matches the string's value? Is it even possible? I think you can do something similar to this in Perl using the evaluate() function, but I don't know how it's done in C or even C++.
Please understand that I am working on something that will have hundreds of functions to choose from, not just the three simple examples I gave. So a massive "case" statement is not a solution I'm looking for :)
Thanks in advance for any help!
Psy