No, since C is a compiled language this is not very easy.
C doesn't work like typical dynamic/scripting languages, which depend on a large run-time environment. Such languages often have a function (in Perl and Python, it's called [eval()
]) that does what you want, but C can't do that since the compiler is not left "inside" the compiled program, it is a separate (and fairly large) program.
C can be compiled to run without any kind of external environment, but even when you do include it the C runtime is much smaller than the compiler, typically.
You're going to have to either call the actual compiler from your program, or do it all yourself.
Calling the compiler of course requires that you know exactly which compiler to use, and that it is even usable from the command-line. Then you can use e.g. system()
to call the compiler, and then add code to check that the ouput was properly generated, and use another system()
function call to run the newly generated program. Sharing data between your program and the newly compiled one will be very complicated.
Doing it youself requires familiarizing yourself with many of the tasks done by a compiler, such as tokenizing, parsing, and evaluating parse trees. These are large complex subjects and not easily shown by example here.