Solved

clear screen

Posted on 1998-05-13
8
290 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now