The clrscr() function is used to clear the MS-DOS console screen on older C compilers like Turbo C and Turbo C++. However, clrscr() is not a standard C function, which means that if you try to compile a program containing clrscr() on modern compilers such as GCC or Clang, you will encounter an error like 'function not declared' or 'not declared in this scope.' So, what should you do when you want to clear the console screen in your program? In this guide, we will show you how to replace the clrscr() function with the system() function, which clears the screen in C programming.
Steps

Add the header file stdlib.h to the code. The system() function is used to pass commands to the terminal or console. This function is declared in the stdlib.h header file.
- The clrscr() function is defined in the conio.h header file. We will remove the clrscr() function and replace it with system(), so you can also remove the conio.h file.

Replace the clrscr() function with system("cls") on Windows. The cls command clears the console screen when executed in the Windows command prompt. When passed through the system() function, the cls command will clear the screen efficiently.

Replace the clrscr() function with system("clear") on Linux or macOS. The system() function sends the clear command to the terminal. On Linux (as well as macOS), the clear command is used to clear the terminal window, which is why the system("clear") function will clear the terminal screen.