
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How to clear console in C?
There are several methods to clear the console or output screen and one of them is clrscr() function. It clears the screen as function invokes. It is declared in “conio.h” header file. There are some other methods too like system(“cls”) and system(“clear”) and these are declared in “stdlib.h” header file.
Here is the syntax to clear the console in C language,
clrscr(); OR system(“cls”); OR system(“clear”);
Here is an example to clear the console in C language,
Let’s say we have “new.txt” file with the following content −
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
Now, let us see the example.
Example
#include<stdio.h> #include<conio.h> void main() { FILE *f; char s; clrscr(); f=fopen("new.txt","r"); while((s=fgetc(f))!=EOF) { printf("%c",s); } fclose(f); getch(); }
Output
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
In the above program, we have a text file “new.txt”. A file pointer is used to open and read the file. It is displaying the content of file. To clear the console, clrscr() is used.
clrscr(); f=fopen("new.txt","r"); while((s=fgetc(f))!=EOF) { printf("%c",s); }
- Related Articles
- How to clear console in MongoDB?
- How can I clear console using C++?
- How to Clear the JavaScript Console in Google Chrome
- How to clear screen using C#?
- How to change BufferWidth of the Console in C#?
- How to change BufferHeight of the Console in C#?
- How to play Beep sound through Console in C#?
- How to read a line from the console in C#?
- How to use WriteLine() method of Console class in C#?
- How to use ReadKey() method of Console class in C#?
- How to change the CursorLeft of the Console in C#?
- How to change the CursorSize of the Console in C#?
- How to change the CursorTop of the Console in C#?
- How to change the WindowHeight of the Console in C#?
- How to change the WindowTop of the Console in C#?

Advertisements