Like it says in the title im having problems with putting a 2D array into a function.
Im not sure on the syntax of putting an array into a function and using it, any help is much appreciated!
Thanks in advance!
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
void updateGrid(char grid[][]);
int height = 2, width = 2;
int main(int argc, char *argv[])
{
// CREATES A GRID 2X2 AND POPULATES IT
char grid[height][width];
grid[0][0] = 'a';
grid[0][1] = 'b';
grid[1][0] = 'c';
grid[1][1] = 'd';
for(int i = 0; i < height; i++)
{
for(int j = 0; j<width; j++)
{
cout << grid[i][j];
}
cout << endl;
}
// to run function type update
string str;
cout << "type update to run function:";
cin >> str;
if(str == "update")
{
cout << "\n\n\n";
updateGrid(grid[][]);
}
system("PAUSE");
return EXIT_SUCCESS;
}
void updateGrid(char grid[][])
{
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
cout << grid[i][j];
}
cout << endl;
}
}