function and readdata()

thanks
Last edited on
can any senior help me please?..
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(const char *filename);, where the `matrix' class holds the dimension and a pointer to the allocated data.


Also, main must return int
u mean i have to create matrix.h or ?

can i just do it just like my **a[][] ?

I don.t have any idea for the matrix . and const char *filename instread or string*filename? since im using string as my filename that user input..
int** readData(const char *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(const char *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)
the input you using is the

cin>>dimension?

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..
I hope that my readData()
is read the Data and store the input as dynamic 2d array or what instead.

since that at Display function. i have to compare with my boolean function that where the magic square is or not .

sorry and for the bother
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);
sorry for my bad explaination sir !

Where should I put the
1
2
3
int dimension;
int **matrix = readData("magic.txt", dimension);
Display(matrix, dimension);


at?

and
 
int** createMatrix(int rows, int columns);


isnt just declare at main of top .
and then how should i declare the function inside?
sorry and sorry.. try my best and completely lost..
senior. help
Topic archived. No new replies allowed.