{"id":7132,"date":"2025-09-01T00:01:41","date_gmt":"2025-09-01T07:01:41","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7132"},"modified":"2025-09-08T08:46:41","modified_gmt":"2025-09-08T15:46:41","slug":"the-reversing-words-filter","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7132","title":{"rendered":"The Reversing Words Filter"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9734;<\/h2>\n<p>A few months back, this blog&#8217;s monthly Exercise was to <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7042\">write a filter to reverse all text input<\/a>. No matter how much text floated in, the filter gobbled it all up and spewed it back in reverse order. This month&#8217;s challenge is similar, but on a smaller scale.<br \/>\n<!--more--><br \/>\nThe challenge this month is again to write a filter. This filter also reverses text, but only one word at a time.<\/p>\n<p>As a filter, the program doesn&#8217;t prompt for input; it processes standard input until the EOF (end-of-file) is encountered. This operation means that text can be typed directly at the command prompt or redirected from a file or other source. As text is input, words are output backwards:<\/p>\n<p><code>This is text input forwards - and backwards!<br \/>\nsihT si txet tupni sdrawrof - dna sdrawkcab!<\/code><\/p>\n<p>Due to <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3675\">line buffering<\/a>, the backwards text output occurs after the newline is input. Otherwise, each word is output backwards, including words with numbers and containing an apostrophe:<\/p>\n<p><code>Words with numbers abc123def<br \/>\nsdroW htiw srebmun fed321cba<\/code><\/p>\n<p>Above, the &#8220;word&#8221; <code>abc123def<\/code> is processed and output as <code>fed321cba<\/code>.<\/p>\n<p>Here&#8217;s sample output where a word with an apostrophe is processed:<\/p>\n<p><code>Don't try this at home!<br \/>\nt'noD yrt siht ta emoh!<\/code><\/p>\n<p>Getting the basic word-reversing algorithm down is a first step. Adding tests for numbers and apostrophes can be added later, but it&#8217;s still part of the challenge.<\/p>\n<p>Try this exercise on your own before you peek at <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7141\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>sihT emit, eht retlif sesrever laudividni sdrow. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7132\">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-7132","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\/7132","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=7132"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7132\/revisions"}],"predecessor-version":[{"id":7163,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7132\/revisions\/7163"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7132"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7132"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7132"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}