0

I have a multidimensional array (a representation of a matrix). I need to zero out, not the entire array, but a section of it. What's the best method of doing this? I tried using memset, but it just gives me a typecast error.

Example

_matrix[row][column] = memset(
                        _matrix[row][column], 
                        0, 
                        sizeof(_matrix[row][column])
                    );

Declaration

float** _matrix = new float*[NUM_ROWS][NUM_COL];

zeboidlund
  • 9,255
  • 29
  • 114
  • 177

2 Answers2

2

The first parameter to memset() is the address of the location to zero. So:

memset(&_matrix[row][column], ...)

However, in your case the following would be far more straightforward:

_matrix[row][column] = 0.0;
Greg Hewgill
  • 890,778
  • 177
  • 1,125
  • 1,260
0

This is tagged as C++ yet you're not really doing any C++. Why not just do that? Avoid all the lower level memset and direct array nonsense.

I certainly think you should take some of the previous advice and really learn the underlying C, memory access, etc., but in C++ this could simply be avoided.

A quick line of code to get you on your way:

typedef std::vector<std::vector<int> > Array2D;
NuSkooler
  • 5,273
  • 1
  • 31
  • 57