I read the input from file and print it using 2 indices [i][j] but when i try to print using 1 index for linear array, i get wrong output. The file looks like this(numbers separated by tabs):
float** floats = newfloat*[rows];
// floats is an array that contains 'rows' pointers
// floats[i] is a pointer
for (int i = 0; i <rows; ++i)
{
floats[i] = newfloat[cols];
}
for (int i = 0; i<rows; ++i)
{
for (int j = 0; j<cols; ++j)
{
int index = i*cols+j;
std::cout << floats[index] << "\t"; // you print pointers
// printing a pointer shows the address (as hex value)
// furthermore, index is not just in range [0..rows[, but in much larger [0..rows*cols[
}
std::cout << "\n";
}
Besides, you do not have a continuous block for the data; you have a separate block for each row.