--- title: "Ascii Dump" type: "article" slug: "ascii-dump" url: "http://localhost/article/ascii-dump/" markdown_url: "http://localhost/article/ascii-dump.md" published_at: "2025-11-26T20:17:47+00:00" modified_at: "2026-06-21T23:26:05+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "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…" category: - name: "QL Hacker's Journal" slug: "ql-hackers-journal" taxonomy: "category" url: "http://localhost/category/periodicals/ql-hackers-journal/" post_tag: - name: "C (programming language)" slug: "c-programming-language" taxonomy: "post_tag" url: "http://localhost/tag/c-programming-language/" - name: "Full Text" slug: "fulltext" taxonomy: "post_tag" url: "http://localhost/tag/fulltext/" - name: "QL" slug: "ql" taxonomy: "post_tag" url: "http://localhost/tag/ql/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Sinclair QL" slug: "sinclair-ql" taxonomy: "model" url: "http://localhost/model/sinclair-ql/" indiv: - name: "Tim Swenson" slug: "tim-swenson" taxonomy: "indiv" url: "http://localhost/indiv/tim-swenson/" publication_r: id: 33686 title: "QL Hacker’s Journal" type: "periodical" url: "http://localhost/periodical/ql-hackers-journal/" authors_r: - name: "Tim Swenson" slug: "tim-swenson" taxonomy: "indiv" url: "http://localhost/indiv/tim-swenson/" issue: "8" issues_articles: - id: 61544 title: "QL Hacker’s Journal 8" type: "issue" url: "http://localhost/issue/ql-hackers-journal-8/" pubdate: "March 1992" archive_link: true --- # Ascii Dump 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 #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); } ```