Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* simple program to generate a full ASCII-chart on stdout */
- #include <stdio.h>
- enum { TWO = 1u << 1, R1 = 1u << 5, R2 = 1u << 6, R3 = R1 + R2 };
- int main (void) {
- char *special[] = { "(nul)", "(soh)", "(stx)", "(etx)",
- "(eot)", "(enq)", "(ack)", "(bel)",
- "(bs)", "(ht)", "(nl)", "(vt)",
- "(np)", "(cr)", "(so)", "(si)",
- "(dle)", "(dc1)", "(dc2)", "(dc3)",
- "(dc4)", "(nak)", "(syn)", "(etb)",
- "(can)", "(em)", "(sub)", "(esc)",
- "(fs)", "(gs)", "(rs)", "(us)",
- "(sp)", "(del)" };
- /* print heading */
- printf ("Char Dec Oct Hex | Char Dec Oct Hex | "
- "Char Dec Oct Hex | Char Dec Oct Hex\n"
- "--------------------------------------------"
- "-----------------------------------------\n");
- /* print chars */
- for (unsigned i = 0; i < R1; i++) {
- char s1[TWO] = { (char)i+R1, 0 },
- s2[TWO] = { (char)i+R2, 0 },
- s3[TWO] = { (char)i+R3, 0 };
- printf ("%-5s %3d %04o 0x%02x | %-5s %3d %04o 0x%02x | "
- "%-5s %3d %04o 0x%02x | %-5s %3d %04o 0x%02x\n",
- special[i], i, i, i,
- i ? s1 : special[R1], i+R1, i+R1, i+R1,
- s2, i+R2, i+R2, i+R2,
- i == R1 - 1 ? special[R1+1] : s3, i+R3, i+R3, i+R3);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement