Hi, is there any way I can erase the contents of the console?
Thanks,
Printable View
Hi, is there any way I can erase the contents of the console?
Thanks,
Code:for ( int i = 0; i < 50; ++i ) {
putchar('\n');
}
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
It's covered, along with a load of other stuff, in part 2 of my console programming tutorial.
For speed purposes, do the following:Quote:
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.
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.
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.
> 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.
... that's another way to say it ...
Does anyone know where I can download curses.h?
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