You don't want to do that. It's considered rude in command line programs and in all others building up your own screen will replace what's underneath it anyway (at least while your application is running).
There's no platform independent way to achieve it btw (probably because of that) so if you insist you'll have to plow through your compiler documentation to see if there's a function for it and how to call it.
You could of course always figure out the memory location of your screenbuffer and manually poke zeros into each position and hope.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
>I need a function that does the same thing as both CLS and Clear.
#include <stdlib.h>
#include "system.h"
void clear()
{
#if defined(DOS_BASE)
system("CLS");
#elif defined(UNIX_BASE)
system("clear");
#else
#error Unsupported system
#endif
}
Will it work? Probably, provided you define either DOS_BASE or UNIX_BASE in system.h. Is it advisable? No, not really. But I've described why elsewhere, and it's really your decision.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Just to be sure that we are on the same page... the function should only clear the 'output' on the screen... not do anything with the actual program or command prompt. I want to create 'animation' in the command prompt, I have done this before with Batch files by echoing text and then 'cls' and echoing the text in another spot on the line. I want to be able to do the same, by just clearing whats on there and then creating the illusion of animation.
I'm having trouble deciding if you're stupid or just can't read well. We understand exactly what you want. You've had three useful replies and two viable solutions. What need is there to be on the same page if you already have a workable answer?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
At least you can admit it. Kudos.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
if you want to clear selective positions, you'll need to write the text that's there in the background colour to those positions.
This is an age old technique employed by terminal applications on mainframes and it works well.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
>when I use clrscr(); it gives me a linker error that it's undefined.
clrscr is pretty much restricted to Borland compilers. Use another method. I'm sure someone will be happy to share their lame, stupid way of clearing the screen with you.
What exactly are you trying to do and on what system with what compiler? Since this is an implementation-dependent question, it's helpful to know what implementation you're using. Otherwise there's now way I can give you a decent solution.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>To Narue: in your own opinion, what would be a good compiler to use?
Dev-C++ is a good one for Windows, but just about any modern compiler is workable if you know your way around the language and the system.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401