Lance Mason Robinson wrote:
>
> I'm having problems using gettext() and puttext(). I'm trying to use
> them
> to save the screen and restore the screen. Sometimes when I'm running
> the program, it locks up after I call gettext() and sometimes after I
> call puttext(). I was thinking maybe the function is getting confused
> by
> other included files. Here's how I am using it in my program..
>
> void * screen;
> //save screen
> gettext(1,1,80,25,screen);
> //here I am changing the screen, for example in one instance if they
> press
> //F1 it shows a help screen with all the commands available.
> //then after they exit the help screen...
> //restore screen
> puttext(1,1,80,25,screen);
>
> If I remove all the gettext()'s and puttext()'s from my program then
> it
> works great. Any ideas how to fix it? Or alternative methods to save
> & restore the screen state?
>
> Lance
Lance,
Your problem is easy to fix. YOU have to allocate the memory you pass
to gettext. It will use it to store the display info. (The lockups
are due to a memory violation.) The memory space needed for the array
can be calculated the following way:
bytes = number_of_rows * number_of_columns * 2
where number_of_rows = bottom - top + 1
and number_of_collums = right - left + 1
In your example the following lines would do it:
#include <conio.h>
// allocate 80*25*2 = 4000 bytes
void screen[4000];
// save screen
gettext(1,1,80,25,screen);
// your stuff
// ...
//
// restore screen
puttext(1,1,80,25,screen);