Appendix R. ASCII Table

In a book of this sort it is traditional to have an appendix with an ASCII table. This book does not. Instead, here is a short C program that generates a complete ASCII table and writes it to the file ASCII.txt.

Example R-1. A C program to generate an ASCII table

/*********************************************/
/* ascii.c                                   */
/* Generate ASCII table                      */
/* To build: gcc -O2 ascii.c -o ascii-table  */
/*                                           */
/* This utterly trivial program written by   */
/* Mendel Cooper, 04/07                      */
/* I'm not proud of it, but it does the job. */
/* License: Public Domain                    */
/*********************************************/

#include <stdio.h>

#define MAX 255                /* FF hex       */
#define FILENAME "ASCII.txt"   /* Outfile name */

int main()
  {
  int i;
  FILE *fp;

  fp = fopen (FILENAME, "a" );

  for( i = 1; i <= MAX; i++ ) {
     fprintf( fp, "%5d  ", i );
     fputc( i, fp );
     fprintf( fp, "     " );
     if ( i % 5 == 0 )
        fprintf( fp, "\n" );
     }

     fprintf( fp, "\n" );

  return (0);
  } /* Outfile needs a bit of hand-editing for tidying up. */

/* Try rewriting this as a shell script. */
/* Not so easy, huh?                     */

To build (compile) the program: gcc -O2 ascii.c -o ascii-table