{"id":321,"date":"2013-10-01T00:01:26","date_gmt":"2013-10-01T08:01:26","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=321"},"modified":"2013-09-28T11:38:58","modified_gmt":"2013-09-28T19:38:58","slug":"allow-me-to-squeeze-in-here","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=321","title":{"rendered":"Allow Me to Squeeze In Here&#8230;"},"content":{"rendered":"<p>When it comes to editing text, the concept of copy and paste is an old one: You select a chunk of text, choose its new location, then paste in the text. The surrounding text jiggles around to make room. Neat and tidy.<br \/>\n<!--more--><br \/>\nThis month&#8217;s exercise involves programming that copy-and-paste operation. It involves working with strings and pointers, which are closely related so if you are confuzzled by one then you&#8217;ll find yourself cheerfully confuzzeld by the other.<\/p>\n<p>The task is to take this string:<\/p>\n<p><code>That's the biggest spider I've ever seen!<\/code><\/p>\n<p>And insert the text <code><span style=\"color:red\">, nastiest<\/span><\/code> after the T in <code>biggest<\/code> so that the resulting string looks like this:<\/p>\n<p><code>That's the biggest<span style=\"color:red\">, nastiest<\/span> spider I've ever seen!<\/code><\/p>\n<p>(Text coloring on this page is for illustrative purposes.)<\/p>\n<p>As with most programming puzzles, multiple solutions exist. This month I want you to come up with two of them.<\/p>\n<p>Yes, I <em>am<\/em> cruel.<\/p>\n<p>The first solution is the cheat: Don&#8217;t create the string, merely display it. Have the program output the text <code>That's the biggest, nastiest spider I've ever seen!<\/code> one chunk at a time. That&#8217;s the easy way to solve the problem.<\/p>\n<p>The second solution is to create the string in memory, then display the whole thing.<\/p>\n<p>Even with these two tasks, you&#8217;ll find many potential solutions. Some of them involve using pointers, some involve using the various <code>strings.h<\/code> functions, others involves insane solutions no one has yet thought of.<\/p>\n<p>As usual, please attempt the exercises on your own before you look at my suggested solutions, linked to below.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2013\/10\/10exercise1.c\">Solution 1: Display the string<\/a><\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2013\/10\/10exercise2.c\">Solution 2: Build the string, then display it<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inserting one string into another is easy with copy-and-paste, not so easy when you have to code the operation in C. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=321\">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-321","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\/321","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=321"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/321\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}