Xcode Program does not work properly.

Hi.
I am programming on Mac OS X on Xcode. I made a simple program like thees.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <unistd.h>
#include <curses.h>
using namespace std;
int main(int argc, const char * argv[])
{

    for (int i=15; i>=0; i--)
    {
        sleep(1);
        system("clear");
        cout<<i<<endl;
    }
    
    cout<<"BOOM";
    
    return 0;
}

It must count down from 15, but it do not do it. What its wrong with it. Thanks in advance!
Works for me fine. Are you really intend to wait 1 millisecond between counts?
But it white 1 second for me. But instead cleanscreen it prints:
TERM environment variable not set.
15
TERM environment variable not set.
14
TERM environment variable not set.
13
TERM environment variable not set.
12
TERM environment variable not set.
11
TERM environment variable not set.
10
TERM environment variable not set.
9
TERM environment variable not set.
8
TERM environment variable not set.
7
TERM environment variable not set.
6
TERM environment variable not set.
5
TERM environment variable not set.
4
TERM environment variable not set.
3
TERM environment variable not set.
2
TERM environment variable not set.
1
TERM environment variable not set.
0
BOOM
Ah, I did not noticed MacOS in your post. Well, the problem is that your OS/compiler/IDE does not initialise TERM variable. You need either run your program from proper terminal, or scratch system (which you should avoid anyway) and use some library or platform dependend solution.
Like here: http://stackoverflow.com/questions/9348153/clear-screen-in-xcode
Use "Terminal.app":

tcs@localhost:~/src/lisp > echo $TERM
xterm-256color


Or "xterm" if you've the X11 environment installed (generally also shipped by Apple):

tcs@localhost:~/src/lisp > echo $TERM
xterm


@MiiNiPaa
Well, the problem is that your OS/compiler/IDE does not initialise TERM variable.

Which value should the OS/compiler/IDE use?
Depends on terminal used. It is more question for Mac forums.
I'm new in programming and i don't see what i must look like. Can you show me a working code?
1) you can try this:
You can work around this issue by selecting you executable in XCode in the Groups & Files side bar, clicking Info and then the Arguments tab. Here add an environment varaible called TERM with the value xterm-color.
However it is not guaranteed to work.

2) You can run from promer terminal and not Xcode pseudo-terminal. Just launch terminal, navigate to compiled program and run it.

3) Use this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <unistd.h>
#include <term.h>

void ClearScreen()
{
    if (!cur_term) {
        int result;
        setupterm( NULL, STDOUT_FILENO, &result );
        if (result <= 0) return;
    }
    putp( tigetstr( "clear" ) );
}

#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{
    for (int i=15; i>=0; i--)  {
        sleep(1);
        ClearScreen(");
        cout<<i<<endl;
    }
    cout<<"BOOM";
} 
Do not forget to link to either curses or termios libraries.
But now it shows an error message "Conversion from string literal to 'char *' is deprecated" in 11 line and "No matching function for call to 'ClearScreen'" in 22 line.
2) You can run from promer terminal and not Xcode pseudo-terminal. Just launch terminal, navigate to compiled program and run it.

Open a terminal in application Terminal and run first version of your program. This will do it!
Ow...
I didn't see it at first time. Thank you. It's work now.
Topic archived. No new replies allowed.