{"id":43,"date":"2015-07-12T16:20:33","date_gmt":"2015-07-12T15:20:33","guid":{"rendered":"http:\/\/watchdiana.fail\/blog\/?p=43"},"modified":"2015-07-12T16:20:33","modified_gmt":"2015-07-12T15:20:33","slug":"learn-c-the-hard-way-chars-and-strings-and-tigers-and-bears","status":"publish","type":"post","link":"https:\/\/watchdiana.fail\/blog\/2015\/07\/12\/learn-c-the-hard-way-chars-and-strings-and-tigers-and-bears\/","title":{"rendered":"Learn C the Hard Way &#8211; chars and strings and tigers and bears"},"content":{"rendered":"<p>&#8216;Kay.  So now we&#8217;re looking at the char[] without a *.  So I&#8217;m going to guess that the * means multiple argvs of type char[] are available.  Still keeping that on the back burner.<\/p>\n<p>I&#8217;m getting closer to a problem I have on the Arduino, where I want to output in a particular format, binary with 0 padding at the front.  That&#8217;s %05d &#8211; but I don&#8217;t know how to pass the right thing out yet.  Maybe printing it as soon as I calculate it and not trying to pass it back out for the printing later on.  Now I know what printf can do, I&#8217;m happier trying that, although I believe I need sprintf &#8211; stringprint.  Again, not a thing to look at <em>yet<\/em>.<\/p>\n<p>Breaking things for extra credit:<\/p>\n<p>char x = &#8221;; is an error.  Char is explicitly 1 character long.  Related to the &#8221; instead of &#8220;&#8221; I figger.<\/p>\n<p>char x[] = &#8220;&#8221; isn&#8217;t an error.  It&#8217;s 0 length but that doesn&#8217;t really matter.  It&#8217;s initialised as a space for there to be a string, and that&#8217;s that.<\/p>\n<pre>printf(\"\")<\/pre>\n<p> &#8211; sort of funny.  How can you tell if it&#8217;s done anything?  I&#8217;m assuming it exists because the compiled program has some size, and I left it on its own in there, but it&#8217;s a 0-length string.  The compiler doesn&#8217;t like it, but goes for it anyhow, but when you run it nothing appears to happen.<\/p>\n<p>By law I must now link to <a href=\"http:\/\/oglaf.com\/fountain-of-doubt\">Oglaf&#8217;s Fountain of Doubt<\/a>.  (SFW)<\/p>\n<p>Subtle, isn&#8217;t it?<\/p>\n<p>Putting an int into a char results in the character returned being (I guess) ASCII result for that integer value.  So that&#8217;s not broken, but it&#8217;s potentially unexpected.  That&#8217;s how I got H out for integer 72 in an earlier exercise.<\/p>\n<p>According to <a href=\"http:\/\/www.cdf.toronto.edu\/~ajr\/209\/notes\/printf.html\">www.cdf.toronto.edu\/~ajr\/209\/notes\/printf.html<\/a> s is already a char pointer.  I think that&#8217;s just a sign that says &#8216;use this long thing over here&#8217; instead of having to write out what the long thing is in a compressed space.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8216;Kay. So now we&#8217;re looking at the char[] without a *. So I&#8217;m going to guess that the * means multiple argvs of type char[] are available. Still keeping that on the back burner. I&#8217;m getting closer to a problem I have on the Arduino, where I want to output in a particular format, binary [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[7,9,11,13],"class_list":["post-43","post","type-post","status-publish","format-standard","hentry","category-coding","tag-c","tag-coding","tag-learn-c-the-hard-way","tag-things-i-do-because-im-stubborn","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":0,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"wp:attachment":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}