/* 
codes.c This prints out the numerical codes of ASCII characters.
ASCII stands for 'American Standard Code for Information Interchange (ASCII).'

The values of ASCII that are relevant are 32 which is a space to 126 which is the tilde.
The values after 126 are extended characters.
*/

#include <stdio.h>
#include <stdlib.h>

int main(void){

  FILE *fp; /* The file to create */
  int c; /* The char loop */

  // Open the file for writing.
  if( (fp = fopen("codes.htm", "w")) == NULL )
  {
    fprintf(stderr, "Error in writing file to disk");
    exit(-1);
  }
 
  fprintf(fp, "<html>\n<head><title>ASCII Codes</title></head>\n<body>\n");
  fprintf(fp, "<table>");
  fprintf(fp, "<tr><td colspan=\"2\">Character  Code</td></tr>"
         "<tr><td colspan=\"2\">===============</td></tr>");

  // This loops from 32..126 (visible ASCII chars)
  for (c=32; c<127; c++)
  {
    fprintf(fp, "<tr><td>%c</td><td>%4d</td></tr>", c, c);
  }

  fprintf(fp, "</table>\n</body>\n</html>");

  return 0;

}