Try putting curly braces around your for-loop code:
97 98 99 100 101 102 103
for (int r = 0; r < dimension; r++) // row loop
{
for ( int c = 0; c < dimension; c++)
{ // column loop
inFile >> a[r][c]; // read data into matrix
}
}
Also, in order to ignore that first character, do this in your readData function, after opening the file:
inFile.ignore(5, '\n')
This will ignore the first five characters or until it encounters a linebreak, whichever happens first.
Hope that helps.
for (int r = 0; r < dimension; r++) // row loop
{
for ( int c = 0; c < dimension; c++)
{ // column loop
inFile >> *(a[r][c]);
}
}
You are storing pointers in the array, so it will write memory addresses to the file, which are useless when you reopen it.
Using the dereference operator (*), you can get to the value of a pointer.
void Display (int dimension ) // display matrix
{
cout << " Magic Square Program " << endl << endl;
int **a;
a = newint *[dimension];
for(int i=0;i<dimension;i++)
a[i]=newint [dimension];
//¿where do you put any values in the `a' matrix?
for (int r = 0; r < dimension; r++)
{
for ( int c = 0; c < dimension; c++)
{
cout << a[r][c] << "\t "; // display numbers
}
cout << endl;
}
}
The solution of you problem is simple ..you should learn alian language ,That's all..
I am just joking :)
first : If we compile your program on visual c++ ,we got 1 error 8 warnings.
7 warnings come from this train : "C:\\Users\Wendy Chirs\Desktop\Inti\Applied\Assignment 1\Assignment 1\wendy.txt";
you should change It to this new one. "C:\\Users\\Wendy Chirs\\Desktop\\Inti\\Applied\\Assignment 1\\Assignment 1\\wendy.txt";
or simply "C:/Users/Wendy Chirs/Desktop/Inti/Applied/Assignment 1/Assignment 1/wendy.txt";
because to introduce a \(backslash) in a string ,should be presided by another backslash for exemple : cout << "This is a backslash \\, and this is a quotation mark \" " << endl;
The last warning is to use _getch(); instead of getch(); ,This tell you that ,
The function may no longer be supported in a future release(bla bla bla).
The error come from this line inFile.open (fileName);and I think you know why?
The problem of your nice program is that you use **a as a local variable you need to golabalize it!
Also you need to delete the memory you've been taken,It not an error or a warning but It's a big deal .
Finaly I think this new version of your code may works and may helps,
if(The program works fine && you need some explanation) just ask
thanks for your code ya. but i think i use should my own basic standing to done the problem. i get it what you mean d . but i still not yet learn that srand(unsigned(time NULL)) so better i keep learning on it before i use it senior , hehe. and i not really ure how to use the vector as i learn the basic in cplusplus.com only.. thanks.. haha