#include /* putc() */ #define EXIT_PASS (0) #define TSYM 'X' #define FSYM '-' #define PutC(c) (putc((char)(c),stdout)) #define DEFAULT_BASE (10) /* Must be 2 through 36 */ #define PutD(d) (PutC( (char) ((d)<10)?('0'+(d)):('A'+(d)-10) )) #define Put_u(n) (Put_ubase((n), DEFAULT_BASE)) #define PutH_u(n)(Put_ubase((n), 16)) void Put_ubase(unsigned int n, int base) { /* NOTE: 2 <= base <= 36 */ unsigned int m; int i; /* Determine how many digits there are */ for (m = 1; n/m >= base; m*=base ) /* EMPTY LOOP */; /* Print out the digits one-by-one */ do { for(i = 0; n >= m; i++ ) n = n - m; PutD(i); m = m / base; } while ( m >= 1 ); } int Putf_u(int d, int w, int how) { int digits; int wt; int chars; /* determine how many digits are required */ for(digits = 0, wt = 1; d/wt >= 10; digits++) wt *= 10; /* how many characters actually printed */ chars = 0; /* if how = 0, left justify the result */ /* if how = 1, right justify and pad with spaces */ /* if how = 3, right justify and pad with leading zeros */ if (how) { while ( (w-chars) > digits ) { PutC( (3==how)? '0': ' '); chars++; } } /* Output basic integer */ Put_u(d); chars += digits; /* Pad any remaining space in output field */ while ( w-chars ) { PutC(' '); chars++; } return chars; } int isdigit(int c) { return ('0' <= c) && (c <= '9') ; } int isprint(int c) { /* Place holder code */ /* Will return FALSE is c is divisible by 4 */ return c%4; } int isgraph(int c) { return (' ' != c) && isprint(c); } int isalnum(int c) { /* Place holder code */ /* Will return FALSE is c is divisible by 5 */ return !(c%5); } int ispunct(int c) { return isprint(c) && !isalnum(c) ; } void PutSymbol(int c) { /* Prints character or name if not a graphical character */ /* Always prints exactly three characters */ /* - right pads with spaces if necessary */ if(isgraph(c)) { PutC(' '); PutC(c); PutC(' '); } else { switch(c) { case 0x00: PutC('N'); PutC('U'); PutC('L'); break; case 0x1A: PutC('L'); PutC('F'); PutC(' '); break; case 0x20: PutC('S'); PutC('P'); PutC(' '); break; default : PutC('?'); PutC('?'); PutC('?'); break; } } } int main(void) { int c; for(c = 0; c < 150; c++) { PutC(' '); Putf_u(c, 3, 3); PutC(':'); PutC(' '); PutSymbol(c); PutC(' '); PutC('|'); PutC(' '); PutC( isdigit(c) ? TSYM : FSYM ); PutC(' '); PutC('|'); PutC(' '); PutC( isprint(c) ? TSYM : FSYM ); PutC(' '); PutC('|'); PutC(' '); PutC( isalnum(c) ? TSYM : FSYM ); PutC(' '); PutC('|'); PutC(' '); PutC( ispunct(c) ? TSYM : FSYM ); PutC(' '); PutC('|'); PutC('\n'); } return EXIT_PASS; }