函数名: clrscr

功  能: 清除文本模式窗口,清屏的意思,即把之前显示出的文字字符去掉,是clear screen的简写

用  法: void clrscr(void);

程序例:
#include <conio.h>
int main  (void)
{
  int i;
  clrscr();
  for (i = 0; i < 20; i++)
  {
    printf("%d\r\n", i);
  }  
  cprintf("\r\nPress any key to clear screen");
  getch();
  clrscr();
  printf("The screen has been cleared!");
  getch();
  return 0;
}

注意:

①只有在Turbo c 中可以运行 !
②在Turbo C++ 中,需要先另存为(save as).C格式,才能使用。

另解:

在VC中无法调用该函数,有下列办法:
1.  #include <windows.h>
system("cls");
这种办法的缺点是程序额外运行系统程序执行清屏操作,延长了程序执行时间。
 
2.自己写函数,这种办法比较快。
这是从微软MSDN得到的方法:
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; /* here's where we'll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
 
这是我在CSDN里面看到的,并适当的做了添加:
/*清屏函数*/
#include <stdio.h>
#include <windows.h>
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
void MyCls(HANDLE) ;
inline void clrscr(void)
{
HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
MyCls(hStdOut);
return;
}
void MyCls(HANDLE hConsole)
{
COORD coordScreen={0,0};//设置清屏后光标返回的屏幕左上角坐标
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;//保存缓冲区信息
DWORD dwConSize;//当前缓冲区可容纳的字符数
bSuccess=GetConsoleScreenBufferInfo(hConsole,&csbi);//获得缓冲区信息
PERR(bSuccess,"GetConsoleScreenBufferInfo");
dwConSize=csbi.dwSize.X * csbi.dwSize.Y;//缓冲区容纳字符数目
//用空格填充缓冲区
bSuccess=FillConsoleOutputCharacter(hConsole,(TCHAR)' ',dwConSize,coordScreen,&cCharsWritten);
PERR(bSuccess,"FillConsoleOutputCharacter");
bSuccess=GetConsoleScreenBufferInfo(hConsole,&csbi);//获得缓冲区信息
PERR(bSuccess,"ConsoleScreenBufferInfo");
//填充缓冲区属性
bSuccess=FillConsoleOutputAttribute(hConsole,csbi.wAttributes,dwConSize,coordScreen,&cCharsWritten);
PERR(bSuccess,"FillConsoleOutputAttribute");
//光标返回屏幕左上角坐标
bSuccess=SetConsoleCursorPosition(hConsole,coordScreen);
PERR(bSuccess,"SetConsoleCursorPosition");
return;
}
/*测试*/
void main(){
  printf("1111") ;
  clrscr() ;
}

clrscr( )用法的更多相关文章

  1. memcpy函数用法

    memcpy函数用法 .分类: VC++ VC++ mfc matlab 2011-12-01 19:17 14538人阅读 评论(0) 收藏 举报 null 原型:extern void *memc ...

  2. C语言中malloc()和calloc()c函数用法

    C语言中malloc()和calloc()c函数用法   函数malloc()和calloc()都可以用来动态分配内存空间,但两者稍有区别. malloc()函数有一个参数,即要分配的内存空间的大小: ...

  3. strncpy 用法

    strncpy   用法 原型:extern char *strncpy(char *dest, char *src, int n); 用法:#include <string.h> 功能: ...

  4. malloc函数用法

    malloc函数用法 函数声明(函数原型): void *malloc(int size); 说明:malloc 向系统申请分配指定size个字节的内存空间.返回类型是 void* 类型.void* ...

  5. memset函数用法

    1. memset()函数原型是extern void *memset(void *buffer, int c, int count) buffer:为指针或是数组 c:是赋给buffer的值 cou ...

  6. malloc与free函数用法

    在C里,内存管理是通过专门的函数来实现.另外,为了兼容各种编程语言,操作系统提供的接口通常是 C 语言写成的函数声明 (Windows 本身也由C和汇编语言写成). 1 分配内存 malloc 函数 ...

  7. memset用法详解

    原文:http://www.cnblogs.com/PegasusWang/archive/2013/01/20/2868824.html 1.void *memset(void *s,int c,s ...

  8. C语言中函数strcpy ,strncpy ,strlcpy的用法【转】

    转自:http://blog.chinaunix.net/uid-20797562-id-99311.html strcpy ,strncpy ,strlcpy的用法好多人已经知道利用strncpy替 ...

  9. strcat()与strcpy()用法

    1.strcpy (1)原型 extern char *strcpy(char *dest,char *src); (2)用法 #include <cstring> (3)功能 把src所 ...

随机推荐

  1. iOS语音合成

    苹果公司在iOS7中推出了语音合成的技术,无需网络环境也可以实现语音合成. iOS7语音合成的主要的API如下: 1.AVSpeechUtterance,是语音合成的基本单位,它封装影响语音合成的需要 ...

  2. C# 之 无法嵌入互操作类型(Word 或 Excel 操作)

    Microsoft.Office.Interop.Excel.Application eApp = new Microsoft.Office.Interop.Excel.ApplicationClas ...

  3. css笔记13:display用法

    1.代码演示: element.html如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  4. nagios–配置文件

    ngios的配置文件位于/etc/nagios目录下 # ll /etc/nagios 总用量 -rw-rw-r-- nagios nagios 3月 : cgi.cfg -rw-r--r-- roo ...

  5. spl_autoload_register()和__autoload()区别

    这篇文章主要介绍了spl_autoload_register()和__autoload()区别,需要的朋友可以参考下   关于spl_autoload_register()和__autoload(), ...

  6. MySQL中的保留字

    本文转载自:http://www.cnblogs.com/lawdong/archive/2010/08/08/2357903.html ADD ALL ALTER ANALYZE AND AS AS ...

  7. 关于Talend的Patch分支对应Eclipse开发环境的配置总结.

    给产品打patch有时候会遇到很多问题,给产品打patch而且大多数是给很多老版本的Studio打,而且要有对应的patch的开发环境. 但是不巧有些patch对应的git仓库目录结构和一些其他版本的 ...

  8. Delphi7使用ADO直接连接Excel读取数据

    我之前是连接成功的,现在不知道为什么怎样连都失败.最后才知道是Office版本的问题,office2007已经是基于xml的.和以前的不一样. Excel2003的连接字符串: 'Provider=M ...

  9. 核心概念 —— 服务提供者

    1.简介 服务提供者是Laravel应用启动的中心,你自己的应用以及所有Laravel的核心服务都是通过服务提供者启动. 但是,我们所谓的"启动"指的是什么?通常,这意味着注册事物 ...

  10. 一步步搭建自己的轻量级MVCphp框架-(一)什么是PHP框架以及MVC设计模式

    PHP框架 php框架对很多新手而言可能会觉得很难攀越,其实不然 ,只要知道一个框架的流程,明白原理了,基本类似框架都可以看懂,php框架真正的发展要从php5开始了,其实php4时代就有一些框架,但 ...