what if we clear screen ?

If the user don’t use clrscr() or any other function to clear the screen, your output will look like this.

Enter No 1 and No 2:
5 9
Sum Of Two Numbers is = 14
Enter No 1 and No 2:
6 10
Sum Of Two Numbers is = 16

How to clear console in C language?

It is one of the basic need a program may required i.e clear the console during execution time.

Need of a clear console screen :

A console screen must be cleared once its stated objectives have been completed. A user also needs a clear screen for new data. Like any other language, C offers a variety of ways to clear the console screen.

The clear screen method or function not only depends on types of operating systems but also compilers, which include modern as well as older compilers
 

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: 

  1. By Using system(“clear”)
  2. By using a regex “\e[1;1H\e[2J”
  3.  by using clrscr() function
  4.  System(“cls”) 

The following are some of the factors that influence a console’s clear screen:

  1. Type of operating system. 
  2. User compiler new or old.
  3. Need of the user.

Prerequisites :

  1. Some clear screen methods are platform specific. They won’t run on other systems or compilers.
  2. If you are using a visual studio then prefer the system.(“cls”) 

Similar Reads

clrscr()

clrscr() is an abbreviation of the clear screen. It aims to clear the console screen. clrscr() is a library function located in the console input output header file . The previous screen on the console is cleared whenever the clrscr () is invoked in a program. To call the clrscr() function, it must define inside any function or the main function....

what if we clear screen ?

...

system(“clear”)

If the user don’t use clrscr() or any other function to clear the screen, your output will look like this....

system.cls()

like clrscr() function system(“clear”) also used to clear console screen in C. This function can be found in the stdlib.h header file. This method is useful in Linux operating system to clear the console screen. whenever the system(clear) function invokes the program it calls the system shell then a clear operation gets performed....

Using \e[1;1H\e[2J Regex :

...

Conclusion :

like clrscr() ,system(“clear”) we use system.cls() function to clear console screen . This function is present in the standard library header file .whenever system(cls) function invoke in the program it calls system shell then clear operation gets performed. It is supported by all online compiler and GCC compilers....

Contact Us