Hello guys.
When i try to run my code i get the Segmentation fault error. i cant see to find where the problem is....
my goal is to read from a txt file as bellow
2
1 0
0 1
3
1 2 3
3 6 6
5 5 4
as You can see the input file first gives the size of the array(always n x n) then gives the matrix its self. Am sure first i need to make an array that is n x n then import in those empty memory slots the values of the matrix. here is my code. towards the end is where my problem starts....check my second post for code
The seg fault is caused by lines 49-50. Line 50 declares a 2d array with dimensions sizexsize, except that size is unintialized so who knows how big or small it is.
Another problem is that your indention of lines 39 and 41 does not reflect the flow of execution. I suspect you intended to do all three prints in the else case, but you need braces.
Another problem is that even if you fail to open either the input or the output file, you still continue on.
Another problem is that your for() loops go from 0...size inclusive, but the valid array indices are 0...size-1 inclusive.
i see what you mean. i need to do dynamic 2d array that creates the matrices on the fly.
given
2
1 0
0 1
3
1 2 3
3 6 6
5 5 4
when i infile>>size it should automaticly create a 2x2 matrices and read the data after. here is the part am stuck on..i still need to do alot of calculations with this input so am kinda stuck to move on.please help if u can thanks jsmith
well my constructors look like this i havent developed em yet since i cant even import my matrix with given size
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class MatrixCalculator{
public:
double m[ ][ ]
MatrixCalculator(int n); // am not sure which one to use the top or this one.....plus how the to allocate memory for array size n given for this constructor.
int determinant()
Matrixcalculator inearMatrixs(int r, int c); //still have issues going through the array like nesting 2x2 out of 8x8
friend ostream& operator<<(ostream& os, Matrix& matrix);
friend istream& operator>>(istream& is, Matrix& matrix);
}