How to:
1. Buffer output ?
2. Get its size ?
3. Print the buffer ?
#include <stdio.h>
int main(void)
{
printf("Tons of printf lines\n");
// 1. Somehow buffer the output up until this point
printf("The size of the buffer is: %i\n", SIZEOFBUFFER); // 2. Get and print the size of the buffer.
printf("Here is the output:\n\n%s", BUFFER); // 3. Print the buffer.
return 0;
}
may be something like
#define MAX_BUFFER 1000
char BUFFER[MAX_BUFFER];
BUFFER[0] = '\0';
strcat(BUFFER, toPrint);/*toPrint contains whatever u wanted to print*/
/*but check for the buffer content size because if it exceed MAX_BUFFER u wil get seg fault*/
/*do it for every printf("%s", toPrint)*/
printf("The size of the buffer is: %i\n", strlen(BUFFER)); // 2. Get and print the size of the buffer.
printf("Here is the output:\n\n%s", BUFFER); // 3. Print the buffer.