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;
}

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;
}

What is SIZEOFBUFFER and BUFFER in your code and can you explain clearly what you want

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.

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.

Yes, that works. I thought there might be a cleaner way of doing it though. Maybe some keyword that I could use...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.