{"id":3616,"date":"2019-06-01T00:01:45","date_gmt":"2019-06-01T07:01:45","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=3616"},"modified":"2019-06-08T09:41:16","modified_gmt":"2019-06-08T16:41:16","slug":"parse-and-count-words-in-a-string","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=3616","title":{"rendered":"Parse and Count Words in a String"},"content":{"rendered":"<p>This month&#8217;s Exercise is based on code presented in the <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3612\">June 1 Lesson<\/a>: split a string into separate words. The difference is that each word you pluck from the string is followed by the number of letters in that word.<br \/>\n<!--more--><br \/>\nThe code you concoct must churn through a string, identifying when a word starts and stops. When the end of the word is encountered, the number letters in the word is output.<\/p>\n<p>Here&#8217;s the sample string to parse, a quote from Mark Twain:<\/p>\n<p><code>char string[] = \"Training is everything. The peach was once a bitter almond; cauliflower is nothing but cabbage with a college education.\\nMark Twain\\n\";<\/code><\/p>\n<p>The program&#8217;s output looks something like this:<\/p>\n<p><code>Training 8<br \/>\nis 2<br \/>\neverything 10<br \/>\nThe 3<br \/>\npeach 5<br \/>\nwas 3<br \/>\nonce 4<br \/>\na 1<br \/>\nbitter 6<br \/>\nalmond 6<br \/>\ncauliflower 11<br \/>\nis 2<br \/>\nnothing 7<br \/>\nbut 3<br \/>\ncabbage 7<br \/>\nwith 4<br \/>\na 1<br \/>\ncollege 7<br \/>\neducation 9<br \/>\nMark 4<br \/>\nTwain 5<\/code><\/p>\n<p>Each word in the string appears on a line by itself, followed the letters in the word.<\/p>\n<p>As was done in the June 1 Lesson, separator characters are skipped over; blank lines are not output.<\/p>\n<p>Please try this Exercise on your own before you peek at <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3624\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Display words in a string one at a time, followed by the number characters in the word. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=3616\">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-3616","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\/3616","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=3616"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3616\/revisions"}],"predecessor-version":[{"id":3642,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3616\/revisions\/3642"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}