There are several ways to clear the console or output screen, one of which is the clrscr() function. It clears the screen when the function is called. It is declared in the "conio.h" header file. There are some other methods such as system("cls") and system("clear"), which are declared in the "stdlib.h" header file.
The following is the syntax to clear the console in C language:
clrscr(); OR system(“cls”); OR system(“clear”);
The following is an example of clearing the console in C language:
Suppose we have a file called " new.txt" file with the following content:
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
Now, let us look at an 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(); }
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
clrscr(); f=fopen("new.txt","r"); while((s=fgetc(f))!=EOF) { printf("%c",s); }
The above is the detailed content of How to clear console in C language?. For more information, please follow other related articles on the PHP Chinese website!