Is it possible to call a C function, given its name as a string? -
I have seen this question in one of C's puzzles !! Is this possible at all?
How can I call a function, its name is given as string? Is it possible to use string, read with scanf, is used directly to call the function?
I already thought that (strcmp (str, "string") calls the function.
But what is any other approach?
Since there is no function, nor its parameters, I would imagine it something like this: / P>
typedef zero (* foo) (); Struct puzzleFoo {char * function_name; Foo * fn; };
Create a lookup table based on the structure, using the string parameter
struct puzzleFoo * lookup (const char * function_name);
Then repeat through an array / list in search of function_nam
e for puzzleFoo
and the function pointer to fn
.
Comments
Post a Comment