PDF download Download Article PDF download Download Article

The clrscr() function was used to clear the MS-DOS console screen in older C compilers like Turbo C and Turbo C++. clrscr() is not a standard C function—if you try to compile a program that includes clrscr() in a modern compiler like GCC or Clang, you’ll get an error that says “function not declared” or “not declared in this scope." [1] So what if you need to clear the console in your program? This wikiHow article will teach you how to replace clrscr() with the system() function to clear the screen in C.

  1. The system() function is used to pass commands to the terminal or console, and it’s declared in the stdlib.h header file. [2]
    • clrscr() is defined in the conio.h header file. Since we'll be removing clrscr() and replacing it with system() , you can remove the conio.h header file.
  2. 2
    Replace clrscr() with system("cls") on Windows. The cls command, when run at the Windows command prompt, clears the console screen. [3]
  3. Advertisement

Passing cls through the system() function effectively clears the screen. [4]

  1. The system() function will pass the clear command to the console. The Linux command (and thus the macOS command) to clear the console is clear , so system("clear") will clear the console window. [5]

Expert Q&A

Ask a Question
      Advertisement

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      About This Article

      Article Summary X

      clrscr() is not a standard C function. It was only used to clear MS DOS consoles in Borland compilers like Turbo C. If you want to clear the console screen in C, you'll want to use system("clear") for Linux and macOS, or system("cls") for Windows.

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 35,411 times.

      Is this article up to date?

      Advertisement