As long as you don't delete your post afterwards...
As it is, you need to create the matrix with the appropriate dimension before opening the file (¿does that makes sense to you?)
Another possibility is to use matrix readData(constchar *filename);, where the `matrix' class holds the dimension and a pointer to the allocated data.
int** readData(constchar *filename, int &dimension); Note that `dimension' is an output parameter.
The thing is that you can't know the dimension before reading it in the file.
And you will need it to operate.
1 2 3 4 5 6 7
int** readData(constchar *filename, int &dimension){
std::ifstream input(filename);
input>>dimension;
int **matrix = createMatrix(dimension, dimension); //dynamically created
//read
return matrix;
}
and const char *filename instread or string*filename? since im using string as my filename that user input..
Use what you are comfortable with.
However I advice against getting the path inside the function (don't getline(cin,fileName); inside `readData').
That way you could reuse it if you got the name for other means (by instance automatic generation or a textbox)
I request that I dont' want to created manually .
read manually from the text and store it and display as well..
and sorry for my bad programming skill..
the createMatrix is need to defined as? int ?
then how should i put inside my DisplayData function as well? ..
trying for long time ady..
non-stop for 5 hours..
The dimension is obtained from the file. int** createMatrix(int rows, int columns); will do as your 22-24 lines. It simply allocates the needed space (you could have guessed that it should return an int** because that were assigned to)
then how should i put inside my DisplayData function as well? ..
Don't understand you
1 2 3
int dimension;
int **matrix = readData("magic.txt", dimension);
Display(matrix, dimension);