TERM Environment Variable error?

Hi guys,

So I have been working on a Game of Life code the past few days and I have come to something that I am hoping will work. I tried to run it and I am getting an error that says "TERM Environment Variable not set". Here is my code...

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <vector>
#include <unistd.h>
#include <cstdlib>
using namespace std;

// Global variables

const int ROWS=21;
const int COLS=80;
const char ALIVE= 'x';
const char DEAD= ' ';

// Function prototypes 
void generation(vector< vector<char> > &world, vector< vector<char> > &worldcopy);

void display(vector< vector<char> > &world);

bool board(int i, int j);

int main()
{
    vector< vector<char> > world(ROWS, vector<char>(COLS, DEAD));
    vector< vector<char> > worldcopy(ROWS, vector<char>(COLS, DEAD));
    
    // Set the initial alive cell configuration
    
    world[10][5] = world [10][4] = world[9][5] = ALIVE;
    
    while(true)
    {
        system("clear");
        display(world);
        usleep(80000);
        generation(world, worldcopy);
        
        return 0;
    }
    

}


void generation(vector< vector<char> > &world, vector< vector<char> > &worldcopy)
{
    int count=0;
    
    for (int i=0; i<ROWS; i++)
    {
        for (int j=0; j<COLS; j++)
        {
            // Check neighbor cells for life
            if (board(i-1,j+1))
            {
             if (worldcopy[i-1][j+1]==ALIVE)
              {
                count++;
              }
            }
            
            if (board(i,j+1))
            {    
             if (worldcopy[i][j+1]==ALIVE)
              { 
                count++;
              }
            }
            
            if (board(i+1,j+1))
            {
             if (worldcopy[i+1][j+1]==ALIVE)
              {
                count++;
              }
            }
            
            if (board(i-1,j))
            {
             if (worldcopy[i-1][j]==ALIVE)
              {
                count++;
              }
            }
            
            if (board(i+1,j))
            {
             if (worldcopy[i+1][j]==ALIVE)
              {
                count++;
              }
            }
            if (board(i-1,j-1))
            {
             if (worldcopy[i-1][j-1]==ALIVE)
              {
                count++;
              }
            }
            if (board(i,j-1))
            {
             if (worldcopy[i][j-1]==ALIVE)
              {
                count++;
              }
            }
            
            if (board(i+1,j-1))
            {
             if (worldcopy[i+1][j-1]==ALIVE)
              {
                count++;
              }
            }
            
            // Rules
            // Lonliness
            if ((worldcopy[i][j]==ALIVE) && (count==0 || count ==1))
            {
                world[i][j] = worldcopy[i][j];
                world[i][j] = DEAD;
            }
            // Lives to next gen.
            else if ((worldcopy[i][j]==ALIVE) && (count==2 || count==3))
            {
                world[i][j] = worldcopy[i][j];
                world[i][j] = ALIVE;
            }
            // Death by overcrowding
            else if (worldcopy[i][j]==ALIVE && count >3)
            {
                world[i][j] = worldcopy[i][j];
                world[i][j] = DEAD;
            }
            // Birth
            else if(worldcopy[i][j]==ALIVE && count==3)
            {
                world[i][j] = worldcopy[i][j];
                world[i][j] = ALIVE;
            }
        }
    }
}

void display(vector< vector<char> > &world)
{
    
    for (int i=0; i <ROWS; i++)
    {
        for (int j=0; j<COLS; j++)
        {
            cout << world[i][j];
        }
        cout << endl;
    }
}

bool board(int i, int j)
{
    if (i<0 || i>=ROWS)
    {
        return false;
    }
    if (j<0 || j>=COLS)
    {
        return false;
    }
    else
    {
        return true;
    }
}


Can anyone help me identify/fix my problem?
I guess that this is your problem:
1
2
3
4
5
6
7
8
9
while(true)
{
    system("clear");
    display(world);
    usleep(80000);
    generation(world, worldcopy);
        
    return 0;
}  

1. Put return 0; outside of this loop
2. Don't keep a loop that runs for ever, make a variable like bool exit_game (false); and loop while ( !exit_game )
Ok, so the return was just a simple mistake (thanks for catching it). But even after those fixes it still keeps giving me that weird error every time it prints a new output. And also the outputs aren't changing like they are supposed to. Anything else obvious?
http://stackoverflow.com/questions/8470184/what-does-term-environment-variable-not-set-mean
Try googling "TERM Environment Variable not set"
There are a lot of results.
Your terminal configuration must be messed up.
Ok thanks, I am just very new to programming and I am far from a computer wiz so some of that stuff doesn't make much sense to me. Thats the only reason I was posting on here.
This should be a linux question.
What distribution are you on?

One temporary solution is to simply avoid using system ("clear");
Read this article: http://www.cplusplus.com/forum/articles/10515/

Avoid using system (anything);
Topic archived. No new replies allowed.