1. ## Fast clrscr function

Hi!

I want to create a fast clear screen code. This code clears only one row and I don't know why. PLEASE HELP!!!

Here's my code:
Code:
```void clrscr (short x, short y, short EraseLength, short NoOfLines)
{
short i = 0, j = 0;
char Clear[30][85];

for (i = 0; i <= NoOfLines; i++)
{
for (j = 0; j <= EraseLength; j++)
{
Clear[i][j] = ' ';
}
Clear[i][j] = '\0';
}
Clear[i][j] = '\0';
gotoxy (x, y);
printf ("%s", Clear);
}```
I want that printf will be used only once and that the program will clear the selected rows and cells in one shot.

2. Is this function really faster than 'clrscr()'??? And note that you are only printing the first line! Run a loop if you have to print all the contents in the 'Clear' variable.

Code:
```void mclrscr(short x, short y, short EraseLength, short NoOfLines)
{
while(x < EraseLength) {
while(y < NoOfLines) {
gotoxy(x ++, y ++);
putchar(' ');
}
}
}```

3. Your function is slow. Mine is faster but the problem is that clears only one row. But if I put printf into a first for loop, then the printf function will be called NoOfLines times which is not good.

HELP!

EDIT:
shaik786, you did not read my instructions! You must use the printf function and must be used only once.

4. Oops, sorry!

Code:
```void clrscr (short x, short y, short EraseLength, short NoOfLines)
{
short i = 0, j = 0;
char Clear[2500];
int pos = 0;

for (i = 0; i <= NoOfLines; i++)
{
for (j = 0; j <= EraseLength; j++)
{
Clear[pos ++] = ' ';
}
Clear[pos ++] = '\n';
}
Clear[pos] = '\0';
gotoxy (x, y);
printf ("%s", Clear);
}```

5. Hm, not good enough. That '\n' is giving me a headache. You know, the x coordinates of the ' ' character must be the same as the first one. How to align it inside the array?

6. I want that printf will be used only once and that the program will clear the selected rows and cells in one shot.
Then you are not clearing the screen. You're clearing a given box on the screen. As such, you cannot simply use printf to do the job. You need to basicly buffer what is on the screen and manually edit the buffer, changing parts of it.

Quzah.

7. How do I do that?

8. Here's a hint: The Video RAM is at: 0xB800
And I'll assure you, this will be real fast!

9. That's cool but I don't know how to program with asm.

10. You don't need to. You can do it in C as well. Just declare a FAR pointer to this address. and write to this location, as simple as that.

Code:
```main()
{
unsigned char far *addr = 0xB800;

*(addr + 0) = 'S';   /*   ODD Bytes are for colour: *(addr + 1) = 1   */
}```
But check to see if your compiler allows for direct access of this memory.

11. ........ or check to see if your compiler provides pokeb()

12. No, my VC++.NET does not allow that. I need this function to clear the box of a screen for a console program.

13. if code for windows use this :

Code:
```#include <windows.h>
#include <conio.h>

int clrscr()
{

HANDLE hndl = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hndl, &csbi);
DWORD written;
DWORD N = csbi.dwSize.X * csbi.dwCursorPosition.Y +
csbi.dwCursorPosition.X + 1;
COORD curhome = {0,0};

FillConsoleOutputCharacter(hndl, ' ', N, curhome, &written);
csbi.srWindow.Bottom -= csbi.srWindow.Top;
csbi.srWindow.Top = 0;
SetConsoleWindowInfo(hndl, TRUE, &csbi.srWindow);
SetConsoleCursorPosition(hndl, curhome);

return 0;
}```

14. ## HERE"S THE BEST WAY TO DO SO!

being a senior member u must be familiar with the 'int68()'
function in 'C'

just save this function 'cls' in any C file out it in the include folder of your Tc and enjoy it!

this is the fastest onr ,& i mean it.
i have used it.

please don't tell me that u don't know this one.....

void cls()
{
union REGS i,o;

i.h.ah = 6;
i.h.bh = 7;
i.h.ch = 0;
i.h.dh = 24;
i.h.al = 0;
i.h.cl = 0;
i.h.dl = 79;

int86(16,&i,&o);
gotoxy(1,1);
}

15. Unregistered:

This code is for clearing the whole screen. Not good. PLEASE, read my instructions. I need function which will only clear some selected box.

s_ruchit: