Is there a function that erases all data/text in a console window?
Is there a function that erases all data/text in a console window?
Does shutdown() count?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
>Is there a function that erases all data/text in a console window?
I can think of two cases where that would make sense:
1) You're looking at naughty text and your boss or parental unit is headed your way.
2) You want to write annoyware that clears the output of previous programs.
Either way, you're doing something wrong. Find another solution.
My best code is written with the delete key.
3) You want to display stats or some such in a window and want a clean window for it.
If you want to do fancy console stuff, look into either a platform specific function/API, or for a more portable solution, PDCurses.
Ehhh... I wasn't sure how to word it and I knew it wouldn't come out so good, but back when I first ever took c++ in high school I remember we would always do programs that outputted in just a simple console window. I am practicing that again after such a long time and when the program gets so long it is annoying to me how it just keeps scrolling downward with text all over. Anyway, I could have sworn there was a function of some sort that erased or cleared the console window and then the rest of the program would then output and continue on, etc. If there isn't please correct me, but if there is... is there a function for C that does the same thing?
Well you're not going to get an answer until you say which OS / Compiler you're using.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
>is there a function for C that does the same thing?
What compiler and OS are you using?
Sorry, OS is windows XP and compiler is visual studio.net 2003
Well how about that, there's a FAQ already.
http://faq.cprogramming.com/cgi-bin/...&id=1043284385
Just scroll down to the one titled
"WINDOWS CONSOLE OPTION: (Credit: Sunlight)"
Feel free to point at every single function listed, then press F1 to read the fantastic manual on that function. Pretty soon, you'll get the idea about the whole of the win32 console API.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Here's a function taken from the FAQ which will clear the screen. Just call it any time you want to clear the screen.
It's the last option under this FAQ entry: How do I... (Level 1) > Clear the screen?Code:#include <windows.h> void clrscr(void) { COORD coordScreen = { 0, 0 }; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD dwConSize; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); GetConsoleScreenBufferInfo(hConsole, &csbi); FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); SetConsoleCursorPosition(hConsole, coordScreen); }
Thanks all!
>3) You want to display stats or some such in a window and want a clean window for it.
There's a reason that shells support clearing the console directly. Be nice to your users and let them decide. If I want to clear the screen then I won't think twice if your program does it for me. But if I don't want to clear the screen, I'm going to be shopping for a new program shortly after you do it. Why? Mostly because you'll have annoyed me, but partially because a design like that is notoriously inflexible.
My best code is written with the delete key.
Options?
You wouldn't believe how truly annoying some programs which inappropriately clear the screen can be.
Especially when you do things like redirection and pipes.
annoyingprog > results.txt
annoyingprog | filter > results.txt
All manner of wierdness which needs to be filtered out - ugh!
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
>Options?
Don't clear the screen and keep the stats minimal. If you write to stdout without assuming that it's a console, you can use the program as a filter. Then I could search and sort your stats, I could save them to a file, send them to another program or across a network, I could clear the screen myself and send them to a formatter (or write my own to specialize the presentation!)... The options are almost overwhelming, all with a simple change, and it all falls out of removing a feature. See my signature and be enlightened.
My best code is written with the delete key.