Hello all. I am having difficulty getting my program to output data correctly. I have a class member function that is supposed to return the value of a specific member of a struct element based on identification with its (the struct element's) other members.
float MatrixType::valueAt(int i, int j) const
{ // code to return the float value at
// significant location row i col j
if(i == matrix[length].row && j == matrix[length].col)
return matrix[length].value;
// checks to match up row and col to find correct value
else
return 0.0;
} // end accessor valueAt
The matrix[] array is of type struct.
The struct is as follows:
struct oneitem
{
int row, col;
float value;
};
I know that I need to somehow change the count of the array (i.e. length) so that it searches through the entire array of structs to find one with matching row and col. I'm not sure if my if statement for comparison is correct either.
In a broad sense what I am trying to do with this program is input a two-dimensional matrix from .txt file and save only the non-zero values of the matrix into a one-dimensional array of structs. Then I want to take that one-dimensional array of structs and output its values so as to recreate the original two-dimensional matrix. I am effectively trying to take a dense matrix filled with numerous 0s and save it more effeciently (using an array of structs; I'm not up to par with pointers).
I have gotten to the point of reading in all the values perfectly and storing them (I'm fairly certain it's beeing stored correctly). Everytime I output the values, however, I either get a matrix filled with all 0s or I'll get the first non-zero value correct and all other values will be 0.