I want to clean the Console screen every 2 seconds, so I tried to use the following command:system("clear");
but it doesn't clear the screen. also the eclipse does not recognized the file "conio.h" for clrscr() function. I'm using Ubuntu OS. Any suggestions?
Asked
Active
Viewed 2,698 times
0

Tomer Aro
- 175
- 1
- 12
-
See e.g. http://stackoverflow.com/questions/4062045/clearing-terminal-in-linux-with-c-code – Kleist May 31 '15 at 21:22
-
What does `system("clear");` do? What happens when you type `clear` at the command line? (And why do you want to clear the screen every 2 seconds?) – Keith Thompson May 31 '15 at 21:27
-
On Ubuntu, `/usr/bin/clear` is part of the `ncurses-bin` package; is it installed? – Keith Thompson May 31 '15 at 21:51
-
1I'm noticing a lot of your questions have to do with shell-like procedures in C. Is there any reason you've chosen C to accomplish these tasks instead of a shell scripting language (like bash) or at least a higher level language that would make this easier (python or ruby) ? – Ryan Haining Jun 01 '15 at 05:58
1 Answers
1
This has been answered before: How do you clear console screen in C?
Basically, it's not cross-platform. If you're using Ubuntu, this line should work:
printf("\e[1;1H\e[2J");
When the test is:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("\e[1;1H\e[2J");
printf("3\n");
sleep(1);
printf("\e[1;1H\e[2J");
printf("2\n");
sleep(1);
printf("\e[1;1H\e[2J");
printf("1\n");
sleep(1);
printf("\e[1;1H\e[2J");
printf("0\n");
return 0;
}

Community
- 1
- 1

Rúben Sousa
- 1,389
- 10
- 8
-
-
Are you running your program in bash? I just tested it and it worked. I'm on Linux Mint, it's based on Ubuntu. – Rúben Sousa May 31 '15 at 21:31
-
I'm running the program both in Terminal and Eclipse. note that this program is in the child process – Tomer Aro May 31 '15 at 21:37
-