Solved

clear screen

Posted on 1998-05-13
8
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

688 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