No Such Luck wrote:
Is there anyway to literally evaluate the contents of a string in an if
statement?
For example:
int i = 0;
char * str = "i == 0";
if(str) /* I know this doesn't do what I want */
{
}
would be the same as:
int i = 0;
if(i == 0)
{
}
The general application is that I'm in interested in reading if
conditionals from a file, not only the conditional variables but the
conditional operators as well (the whole phrase).
Any ideas appreciated.
Is "don't use C" an idea? I suppose you could generate C
code, compile it from within your program, and go execute
it somehow. I don't think you can do what you want by
interpretering arbitrary strings -- e.g. how do you
associate the string "i" with the variable i?
<Tconsider using a scripting language, eg. perl
and the eval command </T>
-David