[comp.os.msdos.programmer] ReDirecting printf to memory????

shearer@cis.udel.edu (Rob Shearer) (09/30/90)

Hello!   Yet another cryptic question that may sound very weird!

I am interested in making printf (and anything else that would print to
the screen) print to a memory location instead.

I know how to create a variable (I am using TC++ by the way) that 
will let me store data straight into the screen, but right now I would
rather redirect all output to a memory location, then when I want the
data on my screen, to give a command that will swap it in..

For example (Semi-Psuedo Code):

main () {
  unsigned int * scrn;

  scrn = MK_FP(0xb800);         /* Assuming Color Monitor of course */
  scrn[0] = 0x0900+'A';

  printf("Hello, World\n");

}

the scrn[0] will put a white (grey?) A on the screen in the upper left corner.
But I would like to do some remapping so that printf will put 
Hello, World into a variable like scrn so I can copy scrn to the actual
screen memory area at a later time.  The catch is, I am trying to do this
with out changing all my printfs that I have (or any console output be it
printf, putch, putchar etc...)

Any help would be GREATLY appreciated!

-Robb Shearer
shearer@sol.cis.udel.edu

bstone@convex.com (Barry Stone) (10/02/90)

Write a new putc that does what you want it to and explicitly link it
into the program.  Putchar, fprintf, etc., probably all call putc in
the long run.

asylvain@felix.UUCP (Alvin E. Sylvain) (10/03/90)

In article <31926@nigel.ee.udel.edu> shearer@cis.udel.edu (Rob Shearer) writes:
>Hello!   Yet another cryptic question that may sound very weird!
>
>I am interested in making printf (and anything else that would print to
>the screen) print to a memory location instead.
>
>I know how to create a variable (I am using TC++ by the way) that 
[ ... ]

Use sprintf to write to arrays, then printf the arrays.

   char arr [MAX_CHARS]
    ...
   sprintf (arr, "%s", str);
   sprintf (arr [some_offset], "The answer is %d\n", answer);
    ...
   printf (arr);  /* ... to your device, however the heck you want it */

> ...  The catch is, I am trying to do this
>with out changing all my printfs that I have (or any console output be it
>printf, putch, putchar etc...)

Yeah, and I want it to print guaranteed future winning Lotto numbers.
--
-=--=--=--"BANDWIDTH??  WE DON'T NEED NO STINKING BANDWIDTH!!"--=--=--=-
"If you come in at 10am and leave at 7pm one day, then come in at 6am
and leave at 3pm the next day, people will deduce that you are coming in
at 10am and leaving at 3pm every day." --- me

risto@tuura.UUCP (Risto Lankinen) (10/03/90)

shearer@cis.udel.edu (Rob Shearer) writes:

>I am interested in making printf (and anything else that would print to
>the screen) print to a memory location instead.

Hi!

There's a standard C library function 'sprintf', which will do what you're
suggesting.  The parameters are the same as in 'printf', except that before
the format string you'll have to put the address of the target buffer.

Normally, the target buffer is declared as an array of characters, but to
send the output to any memory location, you can use a literal with a type
cast to (char *) .

Terveisin: Risto Lankinen

-- 
Risto Lankinen / product specialist ***************************************
Nokia Data Systems, Technology Dept *  2                              2   *
THIS SPACE INTENTIONALLY LEFT BLANK * 2 -1 is PRIME!  Now working on 2 +1 *
replies: risto@yj.data.nokia.fi     ***************************************

DRWilliams@cup.portal.com (Dave Richard Williams) (10/04/90)

>> rather redirect all output to a memory location

Sounds like a virtual screen handling system to me. 
I don't know how you can handle it directly using printf...
but if you could somehow associate a file with a memory location
you could then reopen standard in as that memory location.. I don't
think you'll be able to handle this under ms-dos though.
 
WAIT A MINUET (musical interlude)
all your printf's could be #define'd to sprintf, but this
would still require modification to your printf calls (addition of 
the address argument)

#define'ing printf to another routine of your choice to do the 
printf to a memory location would work fine for printf, but
the rest of your I/O would be left on the screen..

harry@aeshq.UUCP (Harry Pulley) (10/10/90)

I don't know what application you want your new function for, but the standard
libraries already provide sprintf().

This function works similar to the way that printf() does, except that it will 
write the output to a character buffer instead of the standard output stream.
The programmer specifies the location of the buffer and is responsible for the
prevention of memory overrun.

HCPIV