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:
- By Using system(“clear”)
- By using a regex “\e[1;1H\e[2J”
- by using clrscr() function
- System(“cls”)
The following are some of the factors that influence a console’s clear screen:
- Type of operating system.
- User compiler new or old.
- Need of the user.
Prerequisites :
- Some clear screen methods are platform specific. They won’t run on other systems or compilers.
- If you are using a visual studio then prefer the system.(“cls”)
Contact Us