C++/how to take printout of screen
QUESTION: respected sir,
i have made an program in c. and i want to create a option so that i can have a printout of my output screen from printer.
and i don't want to use the print screen from printer. actually i want to give a command or option in the program itself. is it possible...
if u can help me i will be very thank full to you
ANSWER: The only way I can think to do this is to log all screen output to an array of screen lines you keep in memory. When the user wants to print the output, you send the saved lines in the array to the printer.
---------- FOLLOW-UP ----------
QUESTION: can you tell me how can i do that or give me some example. actually i am not that much expert.
i will be very thank full to you.
You can use sprintf to put the output into a line buffer. printf the lines as you add them to the ring buffer, and when you want to print, write to the printer the number of lines you choose to buffer.
I would use a variable argument printf, like vsprintf, so that you can call a function as printf is called, store into the buffer and write to the screen. Ok, here, it's easier to write code than explain it. The following will buffer 80 lines (forever) and printScreen() will print the last 80 lines. You need to find how to write a line to the printer. I did the rest for you. There is no error checking - you should add some. 256 bytes per line may not be enough (although a printed page only has 80 to 120 characters).
#define LINES_TO_BUFFER 80
void output( const char *fmt, ... )
va_start( va, fmt );
vsprintf( lines[lineCount], fmt, va );
va_end( va );
printf( lines[lineCount] );
if( ++lineCount == LINES_TO_BUFFER )
lineCount = 0;
void printScreen( void )
count = lineCount;
if( lines[ count ][ 0 ] )
// HERE => write line[ count ] to printer!
count = ++count % LINES_TO_BUFFER;
} while( count != lineCount );