开发者

Clearing the Screen in C on Solaris, Linux, Windows and Mac

开发者 https://www.devze.com 2023-02-15 05:09 出处:网络
I am writing a small application in C and want to clear the terminal/dos window of text. So far I have:

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开发者_StackOverflow 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?


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消