{"id":38,"date":"2015-07-12T14:38:41","date_gmt":"2015-07-12T13:38:41","guid":{"rendered":"http:\/\/watchdiana.fail\/blog\/?p=38"},"modified":"2015-07-12T14:38:41","modified_gmt":"2015-07-12T13:38:41","slug":"learn-c-the-hard-way-packing-away-my-ego","status":"publish","type":"post","link":"https:\/\/watchdiana.fail\/blog\/2015\/07\/12\/learn-c-the-hard-way-packing-away-my-ego\/","title":{"rendered":"Learn C the Hard Way &#8211; packing away my ego"},"content":{"rendered":"<p>Ex 5.  I&#8217;m pretty good at copying typing I can see, but unfortunately I&#8217;m also pretty good at remembering what I&#8217;ve seen in previous exercises, so I nearly made the argvs into ints.   Brain managed to pull up at the last minute, though.  However, that&#8217;s one to be very careful of in future.<\/p>\n<p>Line 4, \/this\/ version of the main function needs that combo of ints and chars.  I took a moment realising that that was not a universal truism for main().<\/p>\n<p>Line 5, starting the body of the function, threw me for a loop.  I&#8217;m learning this because I&#8217;m messing with an Arduino for my current project, Sparky.  That means I&#8217;ve been basically copying and pasting and trying to make things work.  So I&#8217;ve seen an if() that had brace pairs and an if() that didn&#8217;t.  For a moment I was trying to over-ride what Zed says.  Obviously here, the {} are only required if there&#8217;s more than one line&#8230;<\/p>\n<p>So I&#8217;m going to believe him.  That&#8217;s a very hard thing for me.  And yeah, a bit later on we&#8217;re told that statements end in ; &#8211; except logic.<\/p>\n<p>What&#8217;s going on in there is that we demand an int be returned, and then we return a 0 at the end, and in between we do all sorts of interesting stuff.  I believe we could type <\/p>\n<pre>void main(int whatever)<\/pre>\n<p> if we wanted to input &#8216;whatever&#8217; and get nothing out.  We&#8217;d just do stuff inside the main function.  That&#8217;s how the Arduino sets things up.  It has void loop() and that loop just goes round and round and round, doing stuff but never actually outputting.<\/p>\n<p>I think the only thing I&#8217;m unsure of is the char *argv[]. The [] means it&#8217;s an array.  (I know that because I&#8217;m working out failure messages for Sparky, and that&#8217;s how they are filed.)  But char* x is different to char *x and the * is worrying me.  Pointer.  It&#8217;s a pointer of some sort.  But is *char a pointer to a character&#8230; well, colour me ignorant.  I&#8217;m guessing, not looking this up.  It&#8217;ll end up explained.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ex 5. I&#8217;m pretty good at copying typing I can see, but unfortunately I&#8217;m also pretty good at remembering what I&#8217;ve seen in previous exercises, so I nearly made the argvs into ints. Brain managed to pull up at the last minute, though. However, that&#8217;s one to be very careful of in future. Line 4, [&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,10,11,13],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-coding","tag-c","tag-coding","tag-fun-with-arch-linux","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\/38","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=38"}],"version-history":[{"count":0,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"wp:attachment":[{"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/watchdiana.fail\/blog\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}