简体   繁体   English

实现clrscr()函数以了解其工作原理

[英]Implementing the clrscr() function to understand its working

I am trying to make the copies of the builtin functions and adding ax 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 (" ") ie space all over the screen or it prints("\\n") over the screen?Or what? 我试图制作内置函数的副本并在其名称中添加ax,以便我能理解每个函数的工作方式。为clrscr()编写函数时,我对其工作方式感到困惑。它是否使用2个嵌套循环并打印( “”),即在整个屏幕上都留有空间,或者在屏幕上打印(“ \\ n”)?还是什么? 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();
}

clrscr() implementation may depend on the environment your console application runs. clrscr()的实现可能取决于控制台应用程序运行的环境。 Usually it sends the ClearScreen control character (0x0C) to the console driver, that actually clears the screen. 通常,它将ClearScreen控制字符(0x0C)发送到控制台驱动程序,该命令实际上会清除屏幕。

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"). 如果您不希望驱动程序处理0x0C,则可以通过调用printf(“ \\ n”)来模拟50次。 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. 但是调用50x80调用poutchar('')与调用clrsrc()并不相似,因为在滚动屏幕内容后,光标将前进一倍,这可能会将光标置于下一行。

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. 最好的方法是想象clrscr()会做什么,并使其发挥作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM