Nhan Tran
Nhan Tran

Reputation: 51

How to clear console in C on Windows using Netbeans+ Cygwin?

I have searched on the Internet but most of the answers suggest using library conio.h which is not available. Can anyone give me answer for this question. Thanks in advance.

Upvotes: 1

Views: 3126

Answers (4)

Avinesh Sharma
Avinesh Sharma

Reputation: 61

Try this:

#include<cstlib>      //or    
#include<stdlib.h>
…


…
system("clear");
…

Note: Frankly I would suggest you to start using Latest Microsoft Visual Studio, you will be able to use all function of c without any issues.

Upvotes: 0

chqrlie
chqrlie

Reputation: 144750

You can try ANSI escape sequences:

printf("\033[2J\033[H");

This clears the terminal window and places the cursor at the top left corner if ANSI escape sequences are supported by the terminal. It works fine in most Unix X11 terminals, on OS/X terminals and on the cygwin terminal.

If your Windows terminal does not recognise ANSI sequences, look at this page to enable it: https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx

If you want a quick and dirty solution, system("clear"); or system("cls"); might do the trick.

Upvotes: 2

NJGuru
NJGuru

Reputation: 1

Try this when you wont to use clear screen:

printf("\e[1;1H\e[2J");

How it works:

  • The \e[1;1H sets the screen to the 1st row and 1st column.
  • The 2J overwrites with " "(Space) all characters currently on the screen.

Upvotes: 0

Ravindra Kharche
Ravindra Kharche

Reputation: 91

If you are on Windows

system("cls");

If you are on Linux/unix

system("clear");

Upvotes: 4

Related Questions