I am having problems with dynamically changing matrix values using pointer.
I have these global declarations :
int row, col = 0;
float** matrixP;
float** matrixT;
float** matrixP_;
Then I have a function to take inputs from the user to populate Any Matrix I want :
void TakeInput(float** matrix, float row, float col) {
// Initializing the number of rows for the matrix
matrix = new float*[row];
// Initializing the number of columns in a row for the matrix
for (int index = 0; index < row; ++index)
matrix[index] = new float[col];
// Populate the matrix with data
for (int rowIndex = 0; rowIndex < row; rowIndex++) {
for (int colIndex = 0; colIndex < col; colIndex++) {
cout << "Enter the" << rowIndex + 1 << "*" << colIndex + 1 << "entry";
cin >> matrix[rowIndex][colIndex];
}
}
// Showing the matrix data
for (int rowIndex = 0; rowIndex < row; rowIndex++) {
for (int colIndex = 0; colIndex < col; colIndex++) {
cout << matrix[rowIndex][colIndex] << "\t";
}
cout << endl;
}
}
Then I have the main function where I am taking inputs and just trying to show matrixP :
int main() {
// Take the first point input
cout << "Enter the row and column for your points matrix" << endl;
cout << "Enter the number of rows : "; cin >> row;
cout << "Enter the number of columns : "; cin >> col;
TakeInput(matrixP, row, col);
cout << "=============================================================" << endl;
// =============================================================
for (int rowIndex = 0; rowIndex < row; rowIndex++) {
for (int colIndex = 0; colIndex < col; colIndex++) {
cout << matrixP[rowIndex][colIndex] << "\t";
}
cout << endl;
}
return 0;
}
Now I am having problem in this part :
for (int rowIndex = 0; rowIndex < row; rowIndex++) {
for (int colIndex = 0; colIndex < col; colIndex++) {
cout << matrixP[rowIndex][colIndex] << "\t";
}
cout << endl;
}
And I got :
// matrixP is throwing access violation error.
Please need a helping hand here to point me out what i am doing wrong here. Thanks in Advance !