Hello,
I'm trying to create a generalized recursive for loop function. I need some way to convert a string into runnable code (preferably through a macro). Here is what I have so far:
Code:
#include<stdio.h>
void recursive_for(int,int,char*);
int main(int argc, char* argv)
{
int start=0;
int end=9;
char* codeString = "printf(\"Hello World %d!\n\",start);";
recursive_for(start,end,codeString);
return 0;
}
void recursive_for(int start, int end, char* codeString)
{
int midpt = start + (end-start)/2;
if(start == end)
to_code(codeString);
else
{
recursive_for(start,midpt,codeString);
recursive_for(midpt+1,end,codeString);
}
}
I need either a function or a macro for to_code that will make the string, codeString, into runnable code. This would give me the following output:
Code:
Hello World 0!
Hello World 1!
Hello World 2!
Hello World 3!
Hello World 4!
Hello World 5!
Hello World 6!
Hello World 7!
Hello World 8!
Hello World 9!
Is this possible? The closest I have found is a macro that will convert code to a string, but I need the exact opposite.
Thanks in advance