Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to make system("cls") work in Xcode?

In Turbo C, I use #include then clrscr () to clear the screen in C. I asked a few people how to do it in C++ and they told me to use system("cls")with #include . I tried that but it's not working in Xcode. I think those commands will only work if used with other compilers. So how do you clear the screen in Xcode? Please give me the C and C++ commands as well as the libraries that I need to include. Thank you!!!

PowerBook G4, Mac OS X (10.4.10), 1 GB RAM

Posted on Jul 31, 2007 9:31 PM

Reply
Question marked as Best reply

Posted on Oct 14, 2007 7:32 AM

I typed #include <curses.h> and system("clear"); and I got this:
TERM environment variable not set.

When I typed #include <curses.h> and system("cls");, I got this:
sh: line 1: cls: command not found

When I typed #include <curses.h> and clear();, I got this:
ZeroLink: unknown symbol '_clear'

I don't know what I missed.
5 replies
Question marked as Best reply

Oct 14, 2007 7:32 AM in response to andlabs

I typed #include <curses.h> and system("clear"); and I got this:
TERM environment variable not set.

When I typed #include <curses.h> and system("cls");, I got this:
sh: line 1: cls: command not found

When I typed #include <curses.h> and clear();, I got this:
ZeroLink: unknown symbol '_clear'

I don't know what I missed.

Aug 1, 2007 6:29 AM in response to Lady777

You want to use the ncurses library. Just include the curses.h system file. Then, call the "clear" function.

The conio functions are only for PCs. MacOS X and all other Unix systems use the termio interface. The curses library make that terminal interface somewhat easier to use. It's use isn't very common these days because most people write Cocoa (or Qt or Java) user interfaces.

Sep 15, 2007 10:46 AM in response to andlabs

FWIW, the clear() call is portable.

The system("clear") or system("cls") approach isn't. On another platform, the direct equivalent is system("type/page nl:"), FWIW.

Porting code that uses system() can get ugly, as it is dependent on the particular shell, and some shells can differ widely and wildly.

I've also seen cases where the created process and the parent process displays can conflict; if the parent is using a curses library, then it's usually best to use curses (directly) to clear the display. Scrolling regions on classic terminals and older applications might not be commonly seen, but they do exist. And they can send a system("clear") into the weeds.

Oct 14, 2007 12:56 PM in response to Lady777

Lady777 wrote:
I typed #include <curses.h> and system("clear"); and I got this:
TERM environment variable not set.


I think this is because Xcode's run log window doesn't normally set the TERM environment variable. I haven't been able to get any screen clearing commands to work in Xcode's run log window so I don't think it acts like a true terminal window. However system("clear") should work in Terminal.app. By the way, calling system() doesn't require curses.

When I typed #include <curses.h> and system("cls");, I got this:
sh: line 1: cls: command not found


Because "cls" is not a valid command in OS X... "clear" is though.

When I typed #include <curses.h> and clear();, I got this:
ZeroLink: unknown symbol '_clear'


Because you didn't link with the curses library... refer to your other thread. Linking with curses and calling clear(); doesn't work for me in Xcodes run log or in Terminal. It runs but it doesn't clear the window. But I'm not familiar with using curses so I could certainly be doing something wrong.

Steve

Message was edited by: Steve Herman1

How to make system("cls") work in Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.