My C++ class assignment (this is just one of six parts) compiles, builds, and runs. The output is only half correct. Can you help me find the error. I've spent about 8 hours trying to debug this, without success.
The first array prints out correctly. The second array is supposed to be rotated 90 degrees(the horizontal values become the vertical values, rotated to the right), but all I get is zeros. The error that eludes me is either in the rotateArray function, or the second printArray function.
hi,
i think your receiving array array2 goes out of scope
and can't be returned from the sort method..
i guess i'd make that method void and declare array2
with the keyword static from the start to make the array
persistent and available to the entire class.
2.6 P4 w/1Gig RAM, Asus P4P 800, nvidia Ti-4200
Tried Fedora Core 1 but performance sucked
Built LFS 5.0 performance 100% better
Finally compiled Kernel and Nvidia driver with Intel icc compiler, now it runs like it should have in the first place!
arrayTwo[3][3] = rotateArrayOne(arrayOne);
...
int rotateArrayOne(int array1[][3]);
It's amazing the program doesn't crash at this point though.
Your routine returns an int (a single integer value) which you then assign to a value outside of the scope of arrayTwo (remember that arrays are zero-based).
Try changing the code to:
Code:
rotateArrayOne(arrayOne,arrayTwo);
...
int rotateArrayOne(int array1[][3], int array2[][3]);
And remove the array2 declaration in the function.
Thanks, truls, that was indeed the problem. I found it while working on another part of the assignment, which also involves arrays. Fixed it there, then went back to this one and fixed it too. Works like a charm. If I'd not found it on my own, your suggestion would have fixed it for me. Thanks again.