I want to use printf for some basic debugging (Yes, I am familiar with gdb, etc.). As printf buffers, a call to fflush(stdout) is required immediately after a printf. I thought of writing a simple wrapper. So the wrapper will be something like this:
flushedPrintf(int noArgs, args to be passed to printf);
I think that the implementation of such a function would be something like this:
void flushedPrintf(int noArgs, args to be passed to printf) {
char *myString = malloc(MAX_LENGTH_DEFINED);
sprintf(myString, ....args to be passed to printf);
printf("%s", myString);
fflush(stdout);
}
I know there are functions/macros like va_list, va_start and va_args but those will require me to parse the printf format string to get the type and I want to avoid doing that. Is there a simple approach? As this is only for debugging purpose, I do not mind having the format type restricted to %d, %f and %s.