Published: 11 Feb 2025 | Reading Time: 4 min read
clrscr in C stands for Clearing the console screen in C programming. It is a fundamental function utilised by developers to maintain a clean interface.
In console applications, the ability to clear the screen is crucial for maintaining a clean and user-friendly interface. As programs output dynamic content, a cluttered screen can confuse users, making it difficult to focus on the latest information. By clearing the screen, the interface with the new screen, helps users interact with the program more efficiently and comfortably.
This function erases all previous outputs, allowing developers to display new information without distractions.
The clrscr() is a predefined function in C used to clear the console screen. It removes all previous text, giving you a clean screen for new outputs. It is defined in the conio.h library, and primarily used in older compilers like Turbo C.
void clrscr(void);
#include <stdio.h>
#include <conio.h>
int main() {
clrscr(); // Clear the screen
printf("Screen cleared!\n");
return 0;
}
Screen cleared!
clrscr() does not take any parameters and does not return a value; it simply performs its operation when called. The clrscr() function is defined in the conio.h header file is a simple method for clearing the console screen in C programming.
The conio.h library originated in the early days of DOS-based programming. It was designed to facilitate console input and output operations, providing functions like getch() and clrscr() for better user interaction.
To use clrscr(), you must include the conio.h header file at the beginning of your C program:
#include <conio.h>
#include <stdio.h>
int main() {
// Print the message with a line break between the parts
printf("Hello Students,\n");
printf("welcome to Nxtwave learning!\n");
return 0;
}
Hello Students,
welcome to Nxtwave learning!
The above program prints Hello Students and the next message starts from a new line and prints the Welcome to Nxtwave learning.
#include <stdio.h>
#include <conio.h> // Include conio.h for clrscr()
int main() {
// Print the first part of the message
printf("Hello Students,\n");
// Clear the screen after the first message
clrscr();
// Print the second part of the message
printf("welcome to Nxtwave learning!\n");
return 0;
}
Hello Students,
welcome to Nxtwave learning!
The program begins by printing the message "Hello Students,". After this, it clears the screen using clrscr(), so that any content already displayed is removed. Once the screen is cleared, the program prints the second part of the message, "welcome to Nxtwave learning!", on a clean screen.
Here are a few examples codes using clrscr in C:
#include <conio.h> // Include the conio.h header
#include <stdio.h>
int main() {
clrscr(); // Clears the console screen
printf("The screen has been cleared!");
return 0;
}
//The screen will be cleared before the message is displayed, and the output will appear mentioned below
The screen has been cleared!
#include <conio.h>
#include <stdio.h>
int main() {
int num1, num2, sum;
clrscr(); // Clears the screen
// Get user input
printf("Enter two numbers: ");
scanf("%d%d", &num1, &num2);
sum = num1 + num2; // Calculate the sum
// Display the result
printf("Sum of the numbers is: %d\n", sum);
return 0;
}
// screen will be cleared
Enter two numbers: 5, 10
Some of the numbers is: 15
#include <conio.h> // Include the conio.h header
#include <stdio.h>
#include <unistd.h> // For sleep function
int main() {
for (int i = 0; i < 5; i++) {
clrscr(); // Clear the screen
printf("Clearing the screen... %d\n", i + 1);
sleep(1); // Wait for 1 second
}
return 0;
}
Clearing the screen... 1
(After 1 second, screen clears)
Clearing the screen... 2
(After 1 second, screen clears)
...
Clearing the screen... 5
#include <conio.h> // For clrscr()
#include <stdio.h>
#include <unistd.h> // For sleep()
int main() {
for (int i = 0; i < 5; i++) {
clrscr(); // Clear screen
printf("Iteration %d\n", i + 1);
sleep(1); // Wait for 1 second
}
return 0;
}
Iteration 1
(After 1 second, screen clears)
Iteration 2
(After 1 second, screen clears)
...
Iteration 5
This program clears the screen 5 times within a loop, prints the iteration number, and then pauses for 1 second before removing the screen again.
#include <conio.h>
#include <stdio.h>
int main() {
int choice;
clrscr(); // Clears the screen
// Display the menu
printf("Menu:\n");
printf("1. Option 1\n");
printf("2. Option 2\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
return 0;
}
Menu:
1. Option 1
2. Option 2
3. Exit
Enter your choice: 2
There are three ways to clear your screen in C programming:
#include <conio.h>
#include <stdio.h>
int main() {
clrscr(); // Clears the screen
printf("It's clean screen!");
return 0;
}
//It will clear the screen first, then display the message below.
It's clean screen!
#include <stdlib.h>
#include <stdio.h>
int main() {
system("cls"); // Windows
// OR
system("clear"); // Linux/Unix
printf("Nxtwave!");
return 0;
}
// It will clear the screen first and then display the message below.
Nxtwave!
The system("cls") clears the screen on Windows, while system("clear") does so on Linux/Unix. The system() function calls the OS shell to execute the command. After clearing, it displays the Nxtwave on the screen.
printf("\e[1;1H\e[2J");
printf("Nxtwave!");
//It will clear the screen first, and then display the message below.
Nxtwave!
The following are some tips developers need to ensure when using the clrscr() function in the C language:
Here are the advantages and disadvantages of clrscr() in C:
In conclusion, the clrscr() function in C programming is a way to clear the console screen. It improves user experience in interactive applications, such as menus and games, by providing a clean display of new information. However, clrscr() is not part of the C standard library and may not be supported across all platforms; developers should consider modern alternatives for cross-platform compatibility.
clrscr() is used to clear the console screen. It helps to remove any previous text on the screen, making it easier to display fresh output. It's beneficial when working with old compilers like Turbo C.
Missing header files or misusing it within program logic can lead to errors.
If your compiler does not support clrscr(), you can use other methods to clear the screen, like system commands. For example, on Windows, you can use system("cls"), and on Unix/Linux, you can use system("clear").
clrscr() is primarily supported on DOS and Windows systems. Its functionality may not be available or behave differently on Unix/Linux platforms.
clrscr() is part of the conio.h library is a non-standard function, mainly used in older compilers like Turbo C.
Complete Guide on String Functions in C - Learn essential string functions in C with syntax, examples, memory rules, and safe practices. Master strlen, strcpy, strcmp, strcat, strstr, and more with clarity. (29 Dec 2025, 5 min read)
Mastering Insertion Sort in C: Code, Logic, and Applications - Understand insertion sort in C with easy-to-follow logic, code examples, and practical tips. Learn how this sorting technique works in real programs. (29 Dec 2025, 6 min read)
Quick Sort Algorithm Explained: Steps, Code Examples and Use Cases - Learn the Quick Sort Algorithm with clear steps, partition logic, Python & C++ code examples, and time complexity explained for students and developers. (28 Dec 2025, 6 min read)
Switch Statement in C: Syntax, Flowchart & Sample Programs - Learn how to use the switch statement in C programming with simple syntax, real-life examples, and use cases. Ideal for beginners and students. (27 Dec 2025, 6 min read)
The Ultimate Guide to Binary Search Algorithm in C - Learn the Binary Search Algorithm with steps, examples, and efficiency insights. Understand how it works in C for fast and accurate data searching. (27 Dec 2025, 8 min read)
Merge Sort in C: A Step-by-Step Guide with Code Examples - Learn how Merge Sort works in C with easy-to-follow examples, step-by-step logic, and code implementation. Ideal for beginners and coding interviews. (26 Dec 2025, 8 min read)
About NxtWave
NxtWave is a learning platform offering industry-recognized certifications and career development programs for students and professionals in technology fields.
Contact Information: