clear screen in c
Posted: Sat Sep 22, 2007 10:17 am
I've been advised to avoid the "system calls" such as
Now for Cygwin, i'm able to make the "programs" pause & clear which do the same thing as the above. Obviously pause isn't exactly like "system("pause")" but it gets the job done well enough for my purposes.
pause:
and clear as:
Is there a way to write "clear()" in a void function, NOT in its own executable like so:
So I can include pause and clear in my own executables?
Because right now, clear in a void function just prints something like "<-[2J" instead of actually clearing the screen.
Code: Select all
int main()
{
system("pause");
system("cls");
return 0;
}
pause:
Code: Select all
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Press [Enter] to continue...";
std::cin.ignore( 256, '\n' );
return 0;
}
Code: Select all
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("\033[2J");
printf("\033[1;1H");
return EXIT_SUCCESS;
}
Code: Select all
void clear()
{
printf( "\033[2J" );
printf("\033[1;1H");
}
Because right now, clear in a void function just prints something like "<-[2J" instead of actually clearing the screen.