Wouldn't this print like the whole element and iterate one sheet at a
time?
It depends on what you have in a sheet. If they are only printable characters (ASCII code between 32 and 126) ending with a null character (0x00), you would get an expected output (1023 characters). But, if your sheet contains non-printable characters you won't get a "good" output; and the print will be cut once a null character (0x00) appears within a sheet.
You can have more control over each char in a sheet if you walk each sheet just as any other array. For example you could treat each sheet as an array of bytes, not just as a string, and dump its contents in hex:
- Walk the
sheets array, and, for each sheet,
- walk it as well, get each individual char, extract top and bottom nibbles, print them.
[Demo]
#include <iostream> // cout
#include <numeric> // iota
const size_t number_of_sheets{5};
const size_t sheet_size{5};
void print(char* sheet)
{
for (int i{0}; i < sheet_size; ++i)
{
auto to_string = [](auto c) -> char {
if (0 <= c and c <= 9) { return c + '0'; }
if (10 <= c and c <= 15) { return c - 10 + 'a'; }
};
auto bottom_nibble{(sheet[i] & 0x0f)};
auto top_nibble{((sheet[i] >> 4) & 0x0f)};
std::cout << (i ? "\'" : "") << to_string(top_nibble) << to_string(bottom_nibble);
}
}
int main() {
static char* sheets[number_of_sheets];
for (int i{0}; i < number_of_sheets; ++i)
{
sheets[i] = new char[sheet_size];
std::iota(sheets[i], sheets[i] + sheet_size, i * 0x11);
std::cout << "Sheet " << i << ": ";
print(sheets[i]);
std::cout << "\n";
}
}
// Outputs:
//
// Sheet 0: 00'01'02'03'04
// Sheet 1: 11'12'13'14'15
// Sheet 2: 22'23'24'25'26
// Sheet 3: 33'34'35'36'37
// Sheet 4: 44'45'46'47'48
sheet?