Or even better yet...
Example:
Code:
#define BUFFERSIZE 4096 // 4k buffer should suffice.
int vsystem(const char *fmt, ...)
{
va_list args;
char buffer[BUFFERSIZE];
args = va_start(args, fmt);
/* A word of warning. This is kind of where it helps to look into a more buffer friendly version of
* vsprintf() since there are issues when you do things like this. Microsoft has vsprintf_s() which
* is more advisable to use than vsprintf() but you sacrifice portability then.
*/
if(vsprintf(buffer, fmt, args) >= BUFFERSIZE)
fprintf(stderr, "A buffer overflow probably already crashed the program. If not, just know that it did happen.");
va_end(args);
return system(buffer);
}
Now you can do nifty things like:
Example:
Code:
vsystem("gcc %s.c -c -o %s.o", user_input, user_input);