There's no redirection of standard output to array of characters (at least as far as I know). However you may use
sprintf
function that works exactly as
printf
but writes to a character array insted of writing to stdout.
You may use a preprocessor macro if you like, but i DON'T recommend it (I'm assuming you are using
gcc
compiler):
#ifdef OUTPUT_TO_CONSOLE
#define PRINT(fmt, ...) printf(format, ## __VA_ARGS__)
#else
#define PRINT(fmt, ...) sprintf(arr, format, ## __VA_ARGS__)
#endif
#define SIZE 1024
int main()
{
char arr[SIZE];
PRINT(("%d",(a+b));
}