How do i make Char without constant value ?
Dec 4, 2015 at 3:52pm UTC
hello how do i make char without constant value n will be typed by user
from this
1 2 3 4 5 6 7 8 9 10 11
#define GRID_WIDTH 11
char grid[GRID_WIDTH * GRID_WIDTH];
void ResetGrid()
{
// Fills the grid with walls ('#' characters).
for (int i = 0; i<GRID_WIDTH*GRID_WIDTH; ++i)
{
grid[i] = '#' ;
}
}
to
1 2 3 4 5 6 7 8 9 10
char grid[n*n];
void ResetGrid()
{
// Fills the grid with walls ('#' characters).
for (int i = 0; i<n*n; ++i)
{
grid[i] = '#' ;
}
Dec 4, 2015 at 4:08pm UTC
In C++ your second snippet using the Variable Length Array is forbidden. So your alternatives are to use a std::vector or use dynamic memory (new/delete).
Dec 4, 2015 at 6:22pm UTC
thanks i got it know
Topic archived. No new replies allowed.