Solved

clear screen

Posted on 1998-05-13
8
293 Views
Last Modified: 2010-08-05
The only way that I know how to clear a the MSDOS screen while executing a program is to print out a bunch of end lines.  Is there a better way to do this that will put the cursor back at the top of the screen when done?
0
Comment
Question by:xandox
8 Comments
 
LVL 1

Expert Comment

by:vsinha
ID: 1177028
try:
#include <conio.h>
//...
clrscr();

let me know if you want further explaination
0
 
LVL 1

Expert Comment

by:vsinha
ID: 1177029
Why rejected? Doesn't work, or you didn't understand it?
0
 

Author Comment

by:xandox
ID: 1177030
I tried using the clrscr() from conio.h but I kept getting errors when I compiled saying that clrscr() was an undeclared identifier.

Am I missing anything else?

0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 5

Expert Comment

by:yonat
ID: 1177031
There is no standard way to do it. You must say what compiler you are using.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1177032
And which operating system, too. Are you talking about a console window in Win95 or Win98 or WinNT? Or are you talking about a DOS window on 16-bit Windows?

.B ekiM


0
 
LVL 11

Accepted Solution

by:
alexo earned 50 total points
ID: 1177033
Under DOS, clrscr() should work.  However, in a Win32 console application there is no API to clear the screen.  It can be faked by a short routine, as explained in KB article Q99261 (reproduced below):

-------------------------------------------------------------------------
 
SUMMARY
=======
 
There is no Win32 application programming interface (API) that will clear the screen in a console application. However, it is fairly easy to write a function that will programmatically clear the screen.
 
MORE INFORMATION
================
 
The following function clears the screen:
 
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;
}

0
 
LVL 11

Expert Comment

by:alexo
ID: 1177034
Some additional comments:
* Don't forget to #include <wincon.h>
* PERR() is a user-supplied function or macro that is supposed to display an error.  Either remove all references to it or write it.  Otherwise the code will not compile.

A DOS window in Win16 is equivalent to a DOS application.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1177035
And the autograder hits again!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question