{"id":360,"date":"2013-11-01T00:01:07","date_gmt":"2013-11-01T08:01:07","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=360"},"modified":"2013-10-19T09:17:14","modified_gmt":"2013-10-19T17:17:14","slug":"test-your-formatting-knowledge","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=360","title":{"rendered":"Test Your Formatting Knowledge"},"content":{"rendered":"<p>In late September and early October, I wrote a series of lessons on how the various <em>printf()<\/em> formatting commands are used. Now it&#8217;s time to put your skills to the test.<br \/>\n<!--more--><br \/>\nAs a review, the four lessons covered the following aspects of the <em>printf()<\/em> function&#8217;s various conversion characters:<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/?p=288\">Integer Output (September 21)<\/a><\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/?p=299\">Floating Point Output (September 28)<\/a><\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/?p=314\">Text Output (October 5)<\/a><\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/?p=327\">Other Output (October 12)<\/a><\/p>\n<p>Feel free to reference those Lessons, which may come in handy as you try to craft code to work this month&#8217;s exercise.<\/p>\n<p>To get you started, here is the program&#8217;s skeleton:<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\nint main()\r\n{   \r\n    int age = 52;\r\n    double nd = 16750588107179.74;\r\n    char *name = \"Barack Obama\";\r\n\r\n\/* Output statements go here *\/\r\n\r\n    return(0);\r\n}<\/pre>\n<p>Your goal is to use various <em>printf()<\/em> statements to generate output exactly like this:<\/p>\n<pre><code>0000000000000052\r\n34\r\n16750588107180\r\n1.675e+13\r\n          Barack\r\nBarack  <\/code><\/pre>\n<p>Use the three variables listed in the skeleton as the basis for the output. You cannot modify the variable&#8217;s values. Instead, use the <em>printf()<\/em> function&#8217;s conversion statements to generate the output.<\/p>\n<p>As I admonish every month, please attempt to solve the exercise on your own before you peek at my solution, shown below.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2013\/11\/11exercise.c\">Exercise Solution<\/a><\/p>\n<p><strong>Note:<\/strong> Yes, I&#8217;m using President Obama&#8217;s name in this code. As I&#8217;ve done since I wrote my first programming book back in the 1990s, I used the current president&#8217;s name in my examples. I did so for Bill Clinton and George W. Bush. It is not a political statement; Mr. Obama is the President and his name is well-known and up for grabs.<\/p>\n<p>Oh, and 52 is his age and the <code>nd<\/code> variable value is the current US national debt.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>See if you can harness the power of the <em>printf()<\/em> function&#8217;s text output formatting power. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=360\">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-360","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\/360","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=360"}],"version-history":[{"count":7,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions"}],"predecessor-version":[{"id":381,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions\/381"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}