It is one of the basic need a program may required i.e clear the console during execution time.
There is function named clrscr() which is included in conio.h and is a nonstandard function and is present in conio.h header file which is mostly used by MS-DOS compilers like Turbo C. It is not part of the C standard library or ISO C, nor is it defined by POSIX.
So what should we use there?
There are two more ways to clear console:
- By Using system(“clear”)
- By using a regex “\e[1;1H\e[2J”
Now question arises which should we use and why:
Using regex is a better way.The reason is its faster execution. By using regex we can perform clear screen operation very fastly in comparison to using system(“clear”).
Below c program will demonstrate how fast regex is then the system(“clear”)
The system(“clear”) is included in stdlib.h and also work only in linux system to use this in window use system(“cls”).
geeks for geeks 9999 Time taken by system("clear") 0.934388 Time taken by regex 0.000001
NOTE:The output time may differ but the difference in both time will always be large.And also run this program only in your system’s console not here.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference Between C Language and LISP Language
- kbhit in C language
- Difference between while(1) and while(0) in C language
- Stopwatch using C language
- fgets() and gets() in C language
- C Language Introduction
- Signals in C language
- Arrays in C Language | Set 2 (Properties)
- lvalue and rvalue in C language
- How to use POSIX semaphores in C language
- Constants vs Variables in C language
- C Programming Language Standard
- A C Programming Language Puzzle
- isupper() function in C Language
- isxdigit() function in C Language
- isalnum() function in C Language
- Features of C Programming Language
- chdir() in C language with Examples
- Difference between Java and C language
- Interesting facts about C Language
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.