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().

clrscr (void)
    DWORD written;
    int i;

    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},
      FillConsoleOutputCharacter (GetStdHandle(STD_OUTPUT_HANDLE), ' ',
        (COORD) {__CONIO_LEFT, i},
    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:


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:


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.