Since I saw you started another thread to try to solve this with vectors, I though I might intervene.
I could probably make this a little tighter, but if you have a function that takes a
2d array and returns an int of lines that are not ALL zero values, you can determine how big your new 2d array will need to be:
#include "stdafx.h"
using namespace System;
int GetNumGoodLines(array<int,2>^ arr_int2d)
{
int intRetVal = 0;
int iHeight = arr_int2d->GetUpperBound(0);
int iWidth = arr_int2d->GetUpperBound(1);
for (int i = 0; i <= iHeight; i++)
{
bool blnAllZeroes = true;
for (int j = 0; j <= iWidth; j++)
{
int ix = arr_int2d[i, j];
if (!ix.Equals(0))
{
blnAllZeroes = false;
break;
}
}
if (!blnAllZeroes)
{
intRetVal++;
}
}
return intRetVal;
}
So if you have the array populated, you can detect the number of good lines by calling the function once.
int main(array<System::String ^> ^args)
{
array<int,2>^ matrice_mixed_nums = gcnew array<int,2>(5,7)
{
{2,2,9,8,7,3,4},
{0,0,0,0,0,0,0},
{3,4,5,7,8,9,6},
{0,0,0,0,0,0,0},
{1,3,4,5,5,5,5}
};
//
int intNumGoodLines = GetNumGoodLines(matrice_mixed_nums);
Console::WriteLine("There are {0} rows to copy", intNumGoodLines);
//
if(intNumGoodLines.Equals(0))
{
return -1;
}
//... more code goes here for the copy