tags:

views:

57

answers:

1

I am trying to make the copies of the builtin functions and adding a x to their name so i can understand each functions working.While writing a function for clrscr() i am confused about how it works.Does it use 2 nested loops and print (" ") i.e space all over the screen or it prints("\n") over the screen?Or what? I tried this:

#include<stdio.h>
#include<conio.h>
void main(void)
{

printf("press any key to make clrscr() work");
getch();
for(int i=0;i<50;i++)
    {
    printf("\n");
    }
    // to make the screen come to 1,1
    gotoxy(1,1);
    getch();
}
+3  A: 

clrscr() implementation may depend on the environment your console application runs. Usually it sends the ClearScreen control character (0x0C) to the console driver, that actually clears the screen.

The driver knows about character space to clear as well as all attributes (blink, underline,...) to reset.

If you dont want the driver to handle 0x0C, you can mimic this with 50 times calling printf("\n"). but calling 50x80 calling poutchar(' ') is not similar to calling clrsrc(), since the cursor will be advanced by one what may put it in the next line after scrolling the screen content.

Further you should regard, that the behaviour of the screen depends on the implementation. When the cursor position is in the right column and you output one character the cursor position may stay at the right edge or it may cause a new line. Whe you cursor position is in the lower right corner the next character may cause a new line including scrolling the screen content by one line.

The best way would be to imaging what clrscr() would do and let it make it's job.

harper