
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Clear Console in C
In C, we have various 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.
Syntax
Following are the list of syntaxes to clear the console in C programming language as follows:
clrscr();
Or,
system("cls");
Or,
system("clear");
Let's say we have "new.txt" file with the following content:
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
Example to Clear Console
Following example shows the usage of clear console in C.
#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(); }
The above program produces the follwing result:
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
Explanation
Here, we have a text file named "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); }
Advertisements