Hello sir...
I want to know that if we can make a function that exactly works as clrscr()
if yes then please give me some idea to implement that..I will try that...

This may be some help. Below is the code inside conio.h for clrscr().

void
clrscr (void)
{
    DWORD written;
    int i;

    __fill_text_info();
    for (i = __CONIO_TOP; i < __CONIO_TOP + __text_info.screenheight; i++) {
      FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
        __FOREGROUND + (__BACKGROUND << 4), __text_info.screenwidth,
        (COORD) {__CONIO_LEFT, i},
        &written);
      FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ',
        __text_info.screenwidth,
        (COORD) {__CONIO_LEFT, i},
        &written);
    }
    gotoxy (1, 1);
}

I figure you could just use that, or tweak it to your liking.

The rest of the conio.h code can be seen here, if its any help to you:

http://www.koders.com/c/fid12B9A807D44B53AC7E91A80A8E2AB595FA3992B7.aspx

Sir thanx for your help...but I want to make a simple C function that clears the screen...I dont want to use the definition of clrscr() written in conio.h...

It could be just as simple as:

for(i=0;i<LinesOnYourScreen;i++)
  putchar('\n');

There is no magic command to clear a screen that I know of. You can either write out a space (that is, a blank space with the current background color), or you can output newlines.

You should use unbuffered output to the screen, and something inherently faster than printf().

This article has been dead for over six months. Start a new discussion instead.