#include <iomanip>
#include <iostream>
usingnamespace std;
int main()
{
// It is convenient to use typedefs to simplify your complex array type
// (Sometimes it is necessary, but it isn't in this case.)
typedefunsignedchar byte;
typedef byte eight_bytes[ 8 ];
// Here's our prototype in the nice, easy-to-read way (using our typedefs)
void print( eight_bytes*, unsigned );
// Here we get our data from the heap
// (But you could get it from anywhere, I guess...)
eight_bytes* three_of_eight = new eight_bytes[ 3 ];
// Lets set the array to be filled with numbers of the form: i 0 j
for (unsigned i = 0; i < 3; i++)
for (unsigned j = 0; j < 8; j++)
three_of_eight[ i ][ j ] = i*100 + j;
// Elephant, duh.
print( three_of_eight, 3 );
// Don't forget to clean up
delete [] three_of_eight;
return 0;
}
// Here's our function without the nice, fancy typedefs to make life pretty
void print( unsignedchar a[][ 8 ], unsigned size )
{
cout << setfill( '0' );
for (unsigned n = 0; n < size; n++)
{
for (unsigned m = 0; m < 8; m++)
cout << setw( 3 ) << (int) a[ n ][ m ] << " ";
cout << "\n";
}
}
Remember, the pointer on line 17 need not be aimed at memory on the heap. You could easily aim it at something simple, like a flat (1D) array with your data, or whatever it is you want to access the bytes of.