I'm trying to solve the problem of creating a two-dimensional dynamic array. But it produces an error on the line arr[h][g] = rand() % 20; (second function). Tell me what's wrong.
#include "stdafx.h" #include <iostream> #include <time.h> #include <iomanip> #include <cstdlib> int **stvor(int h,int g); void organiz(int h, int g, int **arr); void del(int h, int g, int **arr); using namespace std; int **stvor(int h, int g){ int **arr = new int *[h]; for (int i = 0; i < h; i++) { arr[i] = new int[g]; } return arr; } void organiz(int h, int g, int **arr) { for (int i = 0; i < h; i++) for (int j = 0; j < g; i++) { arr[h][g] = rand() % 20; cout << setw(6) << arr[h][g]; } return; } void del(int h, int g, int **arr) { for (int i = 0; i < h; i++) { delete[]arr[g]; } delete[]arr; } int _tmain(int argc, _TCHAR* argv[]) { srand((signed)time(NULL)); int **mas; int n, m; cout << "input m = "; cin >> m; cout << "input n = "; cin >> n; cout << endl; mas = stvor(m, n); organiz(m, n, mas); del(m, n, mas); system("pause"); return 0; }
for (int j = 0; j < g; i++), should bej++- andy.37