{"id":7042,"date":"2025-07-01T00:01:23","date_gmt":"2025-07-01T07:01:23","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7042"},"modified":"2025-07-08T21:06:16","modified_gmt":"2025-07-09T04:06:16","slug":"the-reversing-filter","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7042","title":{"rendered":"The Reversing Filter"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9734;<\/h2>\n<p>Filters are fun to code and useful, such as the <em>more<\/em> filter in Linux that pages text output. For this month&#8217;s Exercise, your task is to write a text reversing filter. This program is a bit more challenging than coding other types of filters.<br \/>\n<!--more--><br \/>\nAs a review, a filter takes standard input, modifies it somehow, then generates standard output. This approach allows for text to be read directly from the terminal, input from a file, or redirected as output from another program. It&#8217;s this flexibility that makes filters so useful.<\/p>\n<p>A common filter example is the Caesarian Cypher, which I <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=190\">wrote about<\/a> a dozen years ago. (It was the August 2013 Exercise post.) This filter takes text and rotates the letters 13 positions to encrypt. Re-running the encrypted text through the same filter decrypts, which makes it useful but not a completely foolproof encryption method.<\/p>\n<p>Most filters I&#8217;ve written about in this blog are simple I\/O filters. But the task at hand is to reverse all input and generate output. For example, the following text is input:<\/p>\n<p><code>This is a test<\/code><\/p>\n<p>The filter generates this output:<\/p>\n<p><code>tset a si sihT<\/code><\/p>\n<p>The rub here is that the input text must be stored so that it can be processed in reverse order. This hurdle is what elevates your task beyond just writing a simple I\/O filter.<\/p>\n<p>No, you can&#8217;t cheat by having the filter output a &#8220;buffer full&#8221; message or something equally snarky. The filter must handle all input, whatever size, then regurgitate the input in reverse order for the output.<\/p>\n<p><a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7053\">Click here<\/a> to view my solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Write a filter to output text in reverse. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7042\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-7042","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7042","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=7042"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7042\/revisions"}],"predecessor-version":[{"id":7073,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7042\/revisions\/7073"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}