1

I am writing a small application in C and want to clear the terminal/dos window of text.

So far I have:

  if (system("cls"))
    system("clear");

Which seems to work fine on just about everything except Mac, which gives me the error:

sh: cls: command not found TERM environment variable not set.

Whats weird, is that clear from the terminal works, but not system(clear); and I am not sure why.

Does anyone know how I can stop this, or modify my code to clear the screen on a Mac terminal which will work on other ANSI C compliant compilers, without, obviously, writing a bunch of '/n's to the console?

Ash
  • 24,276
  • 34
  • 107
  • 152
  • possible duplicate of [How do I clear the console in BOTH Windows and Linux using C++](http://stackoverflow.com/questions/228617/how-do-i-clear-the-console-in-both-windows-and-linux-using-c) –  Mar 08 '11 at 01:14
  • What if some user wants to pipe to/from your small application? `cat somefile | yourApp | grep foobar` ??? Can you do without clearing the screen? – pmg Mar 08 '11 at 01:16
  • Well, since I am learning C, I am more concerned with learning how to clear it, than whether or not a user wants to pipe to/from my application! ;) – Ash Mar 08 '11 at 01:19

1 Answers1

4

It turns out this is a problem with compiling and running inside XCode. When compiled and run outside XCode, the code works as expected. Doh!

Ash
  • 24,276
  • 34
  • 107
  • 152