   hello
  I was writing output for a Tic Tac Toe board, and it compiles fine and everything, but it doesn't want to give the right output. It gives a bunch of jumbled letters rather than -, X, or O. Here's my code.[source = 'C++']#include <iostream>using namespace std;enum valid {OPEN, X, O}; //State of the cellenum state {WIN, LOSS}; //State of the game i.e. Win or lossstruct cell { //Creates a cell, with a state of open, x or o  valid cellv;};struct board { //creates a board, with an array of cells, a statistic of the board, saying win or loss, and a drawing function  cell bcell[3][3];  state bstate;  void draw();};void board::draw() { //drawing of the board, accounting for taken spaces  char cellstate[4][3];  for(int y=0; y<3; y++) {    for(int x=0; x<3; x++) { if(bcell[x][y].cellv == OPEN) {   cellstate[x][y] = '-'; } if(bcell[x][y].cellv == X) {   cellstate[x][y] = 'X'; } if(bcell[x][y].cellv == O) {   cellstate[x][y] = 'O'; }    }  }  for(int i=0; i<3; i++) {    cellstate[4] = '\0';  }  for(int y2=0; y2<3; y2++) {    for(int x2=0; x2<3; x2++) { cout<<cellstate[x2][y2];    }  }};int main() {  board MyBoard;  MyBoard.draw();  return 0;}
  1° "Hello" is not a very descriptive (or attracting) thread title2° What is the initial value of the elements of bcell and cellstate? Considering this, what is the value of the elements of cellstate right before you display it?   ;  You aren't setting your data to anything on initilization, so when it comes time to draw the board your actually spitting out what data that was in the memory before it was allocated to your bcell array.  Try something like:void board::clear() {  for(int y=0; y<3; y++)    for(int x=0; x<3; x++) cellstate[x][y] = OPEN;}int main() {  board MyBoard;  MyBoard.clear();  MyBoard.draw();  return 0;};  ofcourse Tok means initializing bcell, (not cellstate).in order to write more robust code you can add error checkingyou may want to read about writing an assert macro (there is an article here in gamedev i think).for example: if(bcell[x][y].cellv == OPEN) {   cellstate[x][y] = '-'; } if(bcell[x][y].cellv == X) {   cellstate[x][y] = 'X'; } if(bcell[x][y].cellv == O) {   cellstate[x][y] = 'O'; } else ErrorReport("bad cell ?!");