Can't Cast Integer to Char in Char Array
<p>Hey guys, I am trying to practice C++ and while doing so I ran into a problem in my code. I dynamically create a character array and then for each array index, I want to fill that element with an integer. I tried casting the integer to a character but that didn't seem to work. After printing out the array element, nothing comes out. I would appreciate any help, I'm pretty new to this, thanks .      </p>

<pre><code>char *createBoard()
{   
    char *theGameBoard = new char[8];    
    for (int i = 0; i &lt; 8; i++)    
        theGameBoard[i] = (char)i;    //doesn't work

    return theGameBoard;    
}
</code></pre>

<p>Here is how I ended up doing it.    </p>

<pre><code>char *createBoard()    
{    
    char *theGameBoard = new char[8];    
    theGameBoard[0] = '0';    
    theGameBoard[1] = '1';    
    theGameBoard[2] = '2';    
    theGameBoard[3] = '3';    
    theGameBoard[4] = '4';    
    theGameBoard[5] = '5';    
    theGameBoard[6] = '6';    
    theGameBoard[7] = '7';    
    theGameBoard[8] = '8';    

    return theGameBoard;    
}
</code></pre>
