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

'언어 > C' 카테고리의 다른 글

[Linked List] 연결리스트를 활용한 도서관리prog  (0) 2017.02.08
[CubeBite] File_Create_Write 함수  (0) 2017.02.08
[Tip] File I/O Error 다루는 법  (0) 2016.11.05
구조체의 크기와 pragma pack  (0) 2016.10.28
비트필드 구조체  (0) 2016.10.27
Posted by 知彼知己百戰不殆
,