In writing strip_c and converting the file to an ascii file, I needed to know what ascii characters were in the file that I would need to strip out. A number of ascii characters are not used in text files, ones like End of Transmission, Acknowlegement, and so on.
On a Unix system, there is a program called od, for Octal Dump. Od will take a file and output it in Octal, Hexidecimal, or Ascii. It’s usefull to see all non-printing codes. I only used od with the -a (for Ascii) option. I’m not so good at reading Octal or Hex.
Instead of going to a Unix system to check this file out, I decided to write a version of od for the QL. Since I only use od with ascii output, I limited my program to just the ascii option. Of course, I could no longer call my version od, so it is now called ad for Ascii Dump.
The constant WIDTH is the number of ascii characters is printed on a single line. It is set for 10 characters, but you can set it as wide as you want, limited only by your screen width.
/* ad_c
Ascii Dump
Will compile under Small-C
*/
#include <stdio_h>
#define WIDTH 10
main() {
char c, file[30];
int fd, count;
printf("Enter Input File Name : \n");
gets(file);
fd = fopen(file,"r");
if (fd == NULL) {
printf("Did not open file: %s",file);
abort(1);
}
count = 0;
while (( c = getc(fd)) != EOF) {
if ( c == 0 ) printf("nul ");
if ( c == 1 ) printf("soh ");
if ( c == 2 ) printf("stx ");
if ( c == 3 ) printf("etx ");
if ( c == 4 ) printf("eot ");
if ( c == 5 ) printf("enq ");
if ( c == 6 ) printf("ack ");
if ( c == 7 ) printf("bel ");
if ( c == 8 ) printf("bs ");
if ( c == 9 ) printf("ht ");
if ( c == 10 ) printf("lf ");
if ( c == 11 ) printf("vt ");
if ( c == 12 ) printf("ff ");
if ( c == 13 ) printf("cr ");
if ( c == 14 ) printf("so ");
if ( c == 15 ) printf("si ");
if ( c == 16 ) printf("dle ");
if ( c == 17 ) printf("dc1 ");
if ( c == 18 ) printf("dc2 ");
if ( c == 19 ) printf("dc3 ");
if ( c == 20 ) printf("dc4 ");
if ( c == 21 ) printf("nak ");
if ( c == 22 ) printf("syn ");
if ( c == 23 ) printf("etb ");
if ( c == 24 ) printf("can ");
if ( c == 25 ) printf("em ");
if ( c == 26 ) printf("sub ");
if ( c == 27 ) printf("esc ");
if ( c == 28 ) printf("fs ");
if ( c == 29 ) printf("gs ");
if ( c == 30 ) printf("rs ");
if ( c == 31 ) printf("us ");
if ( c == 32 ) printf("sp ");
if ( c >= 33 && c <=126)
{
putchar(c);
printf(" ");
}
if ( c == 127 ) printf("del ");
if ( c >= 128 )
{
putchar(c);
printf(" ");
}
count++;
if ( count > WIDTH ) {
printf("\n");
count = 0;
}
}
fclose(fd);
}
Products
Downloadable Media
Image Gallery
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.