PDF download Download Article
Clear the screen in C language in just 3 easy steps
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."

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.

How do you clear the console in C language?

Add the stdlib.h header file to your code. If you’re on Windows, replace clrscr() with system("cls"). If you’re on Linux or macOS, replace clrscr() with system("clear"). These steps should clear your console window.

  1. The system() function is used to pass commands to the terminal or console, and it’s declared in the stdlib.h header file.[1]
    • 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. Advertisement

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

  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. [2]

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!

You Might Also Like

Get Color in C ProgramGet Color in C Program
Print in C2 Easy Ways to Print in C and C++ Programming
Run C Program in Command Prompt Run a C Program Using Developer Command Prompt
Download, Install, and Use Code::Blocks Download, Install, and Use Code::Blocks
Learn to Program in CA Beginner's Guide to Programming in C
Start Learning C Programming in Turbo C++ IDEStart Learning C Programming in Turbo C++ IDE
Set Up C++ and Write Code on XcodeSet Up C++ and Write Code on Xcode
Compile a C ProgramCompile a C Program
Compile a C Program Using the GNU Compiler (GCC) Use GCC to Compile a C Program on Linux and Windows
Create a Simple Program in C++Create a Simple Program in C++
Delay in CDelay in C
Use CMD (Beginner) Use CMD Command Lines as a Beginner
Create and Delete Files and Directories from Windows Command PromptCreate and Delete Files and Directories from Windows Command Prompt
Find All Commands of CMD in Your Computer Display and Use CMD Commands: A List and Guide
Advertisement

About This Article

Nicole Levine, MFA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Nicole Levine, MFA. Nicole Levine is a Technology Writer and Editor for wikiHow. She has more than 20 years of experience creating technical documentation and leading support teams at major web hosting and software companies. Nicole also holds an MFA in Creative Writing from Portland State University and teaches composition, fiction-writing, and zine-making at various institutions. This article has been viewed 41,624 times.
How helpful is this?
Co-authors: 4
Updated: May 13, 2025
Views: 41,624
Categories: Programming
Article SummaryX

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 41,624 times.

Is this article up to date?

Advertisement