1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype> // for isprint
using namespace std;
//======================================================================
string lineString( char left, char mid, char right, char horz, int wcell, int ncell )
{
string result = "", cell = string( wcell, horz );
result += left;
for ( int i = 0; i < ncell - 1; i++ ) result += cell + mid;
result += cell + right;
return result;
}
//======================================================================
void printRange( const char *title, int i1, int i2, int numPerLine, char unprintable )
{
// ***********************************************************************************
// *** You WILL repeat WILL repeat WILL have to adapt the characters for your system *
// ***********************************************************************************
// char HORZ = '-'; // Should work on all systems
// char VERT = '|'; //
// char TL = '-'; //
// char TM = '-'; //
// char TR = '-'; //
// char BL = '-'; //
// char BM = '-'; //
// char BR = '-'; //
char HORZ = 196; // May have to find the right BOX characters
char VERT = 179; //
char TL = 218; // Top Left etc
char TM = 194; //
char TR = 191; //
char BL = 192; //
char BM = 193; //
char BR = 217; //
int numW = 3; // Width for writing out an integer
int charW = 1; // Width for writing out a character
cout << title << "\n\n";
cout << lineString( TL, TM, TR, HORZ, numW + charW + 3, numPerLine ) << "\n";
for ( int i = i1; i <= i2; i++ )
{
char c = i;
if ( i < 128 && !isprint( c ) ) c = unprintable;
cout << VERT << " " << setw( numW ) << i << " " << setw( charW ) << c << " ";
if ( ( i - i1 + 1 ) % numPerLine == 0 ) cout << VERT << '\n';
}
cout << lineString( BL, BM, BR, HORZ, numW + charW + 3, numPerLine ) << "\n\n";
}
//======================================================================
int main()
{
printRange( "Character set 0-127:", 0, 127, 8, ' ' );
printRange( "Character set 128-255:", 128, 255, 8, ' ' );
}
//======================================================================
|