How do i make Char without constant value ?

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] = '#';
	}

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).
thanks i got it know
Topic archived. No new replies allowed.