Copying an array effectively
807607Oct 3 2006 — edited Oct 3 2006I am writing an accounting system for a class I'm taking at SLU. I need help figuring out the best way to go about copying a 2D array to a temporary 2D array, for eventually copying it back.
Here's my flow of commands:
1. copy a single row of a 2D array
2. change that single row (either add a cell or delete a cell).
3. copy that single row back into the 2D array by the use of a temporary array.
So I'm basically copying a single row from a 2D array, changing that row, copying the 2D array to a temp array, then copying the 2D temp array back into the reinstantiated 2D array with the changed row placed at the correct row.
When I copy the original 2D array to a temp 2D array, any cells in the 2D array that were empty end up as "0's" in the temp 2D array. This isn't what I want. Look at the code below:
LRRdblTempArray = new double[LRRFindNumberofRows(LRRMasterArray)][LRRFindNumberofCols(LRRMasterArray)];
for (int row = 0; row < LRRMasterArray.length; row++)
{
for (int col = 0; col < LRRMasterArray[row].length; col++)
{
LRRdblTempArray[row][col] = LRRMasterArray[row][col];
} // end inner for
} // end outer for
When I print out LRRdblTempArray, I find that there are 0's in the cells that should have nothing in them (aka the original 2D array, LRRMasterArray, had blank cells there).
Thank you for taking the time to read this, and any help from anyone would be greatly appreciated.