Hi, is there any way I can erase the contents of the console?
Thanks,
Should die now
Should let message board nature take it down the list
Hi, is there any way I can erase the contents of the console?
Thanks,
Adam
Acutally IMHO thats not a very good way to clear the console. For one, it moves the cursor to the bottom, and for two you dont know the size of the console window.
Check out http://faq.cprogramming.com
This has been asked a BAziiilliiioooon times, search the faq and the boards you will find many ways, many arguments, many fights, and many other things about clearing the screen.
Thanks
Adam
It's covered, along with a load of other stuff, in part 2 of my console programming tutorial.
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
For speed purposes, do the following:Originally Posted by Antigloss
for (register int i = 0; i < 50; ++i ) {
putchar('\n');
}
The loop control variable is saved as a register in the computer instead of memory, so accessing it will be much more efficient. For today's computers, it's probably not going to be a difference, but you don't know what computer your users will have. Regardless, it's still theoretically faster accessing a register than accessing memory.
Rare is the compiler that's not smart enough to put a loop variable into a register. In fact, a loop with fixed run length will be either unrolled (though 50 iterations might be too many for that), or implemented using the x86 LOOP instruction, which requires the counter to be in the ECX register.
Most modern compilers are, in most situations, better off deciding for themselves which variables go into registers.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Stupid compilers... they think they're so smart...
Microsoft 32-bit compilers ignore the register keyword. I suppose other compiler do too.
Eitehr way, I think it's a good habit to get into, because there's so many systems out in the world that depend on C/C++ code.
According to Microsoft:
The compiler does not honor user requests for register variables; instead, it makes its own register choices when global optimizations are on.
Last edited by dxfoo; 09-07-2005 at 11:02 AM.
I still disagree. The register keyword makes a low-level optimization choice that you shouldn't make until profiling actually shows that there's significant time lost.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
> Eitehr way, I think it's a good habit to get into
ROFLMAO - I seriously doubt you'll find a serious compiler which can't do this.
If you do, you've got other problems to think about.
Such twee micro-optimisations are really a waste of effort nowadays. For a start, you have no idea how many registers are on the current machine (yes, I'm talking about the real world, not the insulated world of wintel).
Besides, you fail to take into account the work inside the loop (lots - I/O is expensive) with the work of the loop itself (almost nothing).
Consider the possibility that the compiler decides to follow your guess as opposed to what it knows is the real register usage, and as a result generates WORSE code than what it would have generated had you not said anything.
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.
... that's another way to say it ...
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Does anyone know where I can download curses.h?
Adam
Well, you can get ncurses here:
http://www.gnu.org/software/ncurses/ncurses.html
It's UNIX-only, though.
Public Domain Curses looks more promising for Windows:
http://sourceforge.net/projects/pdcurses
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law