Home » C Popular & Interesting Questions

How to clear output screen in C programming Language?

Clear Output Screen using C program

Clear Output Screen - When we run a program, previous output or other command prompt/ Linux Terminal command's output appear there. We can clear the output screen using C program.

Functions which are used to clear output screen depend on the compiler, commonly used functions/methods are:

  1. Using clrscr() - For TurboC Compiler
  2. Using system("cls") - For TurboC Compiler
  3. Using system("clear") - For gcc/g++ compiler in Linux

1. Using clrscr() - For TurboC Compiler

clrscr() is a library function declared in conio.h header file. This function clears the output screen.

Consider the following program

#include <stdio.h>
#include <conio.h> /*for clrscr()*/
 
int main()
{
    int num=100;
     
    /*Use after declaration section*/
    clrscr(); /*clear output screen*/
     
    printf("value of num: %d\n",num);
     
    return 0;
}

2. Using system("cls") - For TurboC Compiler

system() is a library function of stdlib.h header file. This function is used to run system/ command prompt commands and here cls is a command to clear the output screen.

Consider the following program

#include <stdio.h>
#include <stdlib.h> /*for system()*/
 
int main()
{
    int num=100;
     
    /*Use after declaration section*/
    system("cls") /*clear output screen*/
     
    printf("value of num: %d\n",num);
     
    return 0;
}

3. Using system("clear") - For gcc/g++ compiler in Linux

system() is a library function of stdlib.h header file. This function is used to run system/ Linux Terminal commands and here clear is a command to clear the output screen.

Consider the following program

#include <stdio.h>
#include <stdlib.h> /*for system()*/
 
int main()
{
    int num=100;
     
    /*Use after declaration section*/
    system("clear") /*clear output screen*/
     
    printf("value of num: %d\n",num);
     
    return 0;
}





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.