>that's funny...
What's funny is that frrossk made the exact same mistake twice, thus ensuring that the solution wouldn't work. The argument to the system function is a string designating a system shell command, so the correct call would be:
system ( "cls" );
However this isnot recommended. While system is a standard function, the argument you pass it can never be completely portable. Most notably is that on DOS and Windows machines, cls will work, but only POSIX machines, clear is the command you need. On top of that, system calls the first program it encounters with a matching name and argument list as specified by the string. So if cls is a malicious program, bad things will happen. If cls is a benign program that does something other than clear the console window, you'll have a strange bug. Finally, system is a slow function. Clearing the screen is usually a common operation in programs that use it, so you want the solution to be as fast as possible. Invoking a system command interpreter is rarely a good idea when there are alternatives.
If you don't care about all of this then I still recommend adding a level of abstraction to make life easier for you down the road:
#include <stdlib.h>
void clear_screen ( void )
{
system ( "cls" );
}
Then scatter calls to clear_screen across your program. When you find the need to move to a different platform, changes only need to be made to the body of clear_screen rather than however many times you would have called system. Isolating the nonportable aspects of your program from everything else is a good habit to get into even if you only use them once or twice.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401