{"id":4910,"date":"2021-08-08T00:01:00","date_gmt":"2021-08-08T07:01:00","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=4910"},"modified":"2021-08-07T08:39:01","modified_gmt":"2021-08-07T15:39:01","slug":"a-handy-ascii-table-solution","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=4910","title":{"rendered":"A Handy ASCII Table &#8211; Solution"},"content":{"rendered":"<p>My ASCII table program had several iterations. It&#8217;s easy to get carried away, but it&#8217;s also easy to be too skimpy on the information. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4895\">This month&#8217;s Exercise<\/a> is based on my current ASCII program, which has evolved over the years.<br \/>\n<!--more--><br \/>\nCoding this challenge doesn&#8217;t require a lot of advanced C programming knowledge. Still, having a handy ASCII table is a necessary thing if you want to confirm code values or explore interesting ASCII tricks.<\/p>\n<p>Central to my solution is a <em>for<\/em> loop, though it goes only from 0 through 32 &mdash; one stick of an ASCII table. The loop contains four <em>printf()<\/em> statements, one for each stick.<\/p>\n<p>The first <em>printf()<\/em> statement doesn&#8217;t output character values directly, as the control codes would foul the display. The second through fourth <em>printf()<\/em> statements increase the value output by 32 each time: +32, +64, and finally +96.<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2021_08-Exercise.c\" rel=\"noopener\" target=\"_blank\">2021_08-Exercise.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\nint main()\r\n{\r\n    int x;\r\n\r\n    printf(\"Dec  Oct  Hex  C&nbsp;&nbsp;&nbsp;\\\r\n&nbsp;Dec  Oct  Hex  C  \\\r\n&nbsp;Dec  Oct  Hex  C  \\\r\n&nbsp;Dec  Oct  Hex  C\\n\");\r\n    for( x=0; x&lt;32; x++ )\r\n    {\r\n        printf(\"%3d  %3o  %3x  - | \",\r\n                x, x, x\r\n              );\r\n        printf(\"%3d  %3o  %3x  %c | \",\r\n                x+32, x+32, x+32, x+32\r\n              );\r\n        printf(\"%3d  %3o  %3x  %c | \",\r\n                x+64, x+64, x+64, x+64\r\n              );\r\n        printf(\"%3d  %3o  %3x  %c \\n\",\r\n                x+96, x+96, x+96, x+96\r\n              );\r\n    }\r\n\r\n    return(0);\r\n}<\/pre>\n<p>The initial <em>printf()<\/em> statement at Line 7, which outputs the header row, is split between lines. The backslash character extends the line, wrapping it around to the following line, but without an indent. The indent would become part of the string, which I don&#8217;t want. Still, be careful to mind the spaces required between the lines to ensure that the headings line up with the columns.<\/p>\n<p>This source code&#8217;s program is named <em>ascii<\/em> and I keep in my personal <code>bin<\/code> directory so that I can always summon an ASCII table while I&#8217;m working.<\/p>\n<p>I hope you concocted a useful ASCII table solution, using whatever methods or approach you deemed best. Remember, multiple solutions are always possible for any programming puzzle.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My ASCII table program had several iterations. It&#8217;s easy to get carried away, but it&#8217;s also easy to be too skimpy on the information. This month&#8217;s Exercise is based on my current ASCII program, which has evolved over the years.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-4910","post","type-post","status-publish","format-standard","hentry","category-solution"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4910"}],"version-history":[{"count":6,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4910\/revisions"}],"predecessor-version":[{"id":4928,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4910\/revisions\/4928"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}