{"id":1761,"date":"2016-02-08T00:01:48","date_gmt":"2016-02-08T08:01:48","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=1761"},"modified":"2016-02-20T09:12:07","modified_gmt":"2016-02-20T17:12:07","slug":"text-parsing-power-solution","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=1761","title":{"rendered":"Text Parsing Power &#8211; Solution"},"content":{"rendered":"<p>This <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=1742\">month&#8217;s Exercise<\/a> hosts a realm of possible solutions. So I present you with my three solutions, two of which are general and one specific.<br \/>\n<!--more--><br \/>\nMy first two solutions use an array to store the start of each word in the sentence: The sentence is scanned front-to-back. I use the <em>isalpha()<\/em> function to test for word boundaries. When a word is found, its location in the string is saved.<\/p>\n<p>After all the words are located, a loop works backwards through the array of stored locations, with each word displayed in reverse order.<\/p>\n<p>That&#8217;s the general approach to my first two solutions. Why two? One uses pointers and the other uses array notation. They both behave in the same way.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2016\/01\/02exercise-pointers.c\"rel=\"\">Click here<\/a> to view the pointer solution.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2016\/01\/02exercise-arrays.c\"rel=\"\">Click here<\/a> to view the array solution.<\/p>\n<p>My third solution is a kludge. It doesn&#8217;t bother to store the start of each word. Instead, text input is scanned backwards. Spaces are replaced by null characters (<code>\\0<\/code>). When a word boundary is found, that word is displayed, the string is truncated again, then the scanning continues to the start of the string.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2016\/01\/02exercise-backwards.c\"rel=\"\">Click here<\/a> to view the backwards-scanning solution.<\/p>\n<p>Additional solutions are possible. As I wrote in the Exercise post, library functions can help you parse a string of text. Next Saturday&#8217;s Lesson offers <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=1758\">a solution<\/a> that uses the <em>strtok()<\/em> function. Later this month, I&#8217;ll post a solution that uses <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=1769\">the <em>strsep()<\/em> function<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This month&#8217;s Exercise hosts a realm of possible solutions. So I present you with my three solutions, two of which are general and one specific.<\/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-1761","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\/1761","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=1761"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1761\/revisions"}],"predecessor-version":[{"id":1792,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1761\/revisions\/1792"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}