Learn C the Hard Way – packing away my ego

Ex 5. I’m pretty good at copying typing I can see, but unfortunately I’m also pretty good at remembering what I’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’s one to be very careful of in future.

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().

Line 5, starting the body of the function, threw me for a loop. I’m learning this because I’m messing with an Arduino for my current project, Sparky. That means I’ve been basically copying and pasting and trying to make things work. So I’ve seen an if() that had brace pairs and an if() that didn’t. For a moment I was trying to over-ride what Zed says. Obviously here, the {} are only required if there’s more than one line…

So I’m going to believe him. That’s a very hard thing for me. And yeah, a bit later on we’re told that statements end in ; – except logic.

What’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

void main(int whatever)

if we wanted to input ‘whatever’ and get nothing out. We’d just do stuff inside the main function. That’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.

I think the only thing I’m unsure of is the char *argv[]. The [] means it’s an array. (I know that because I’m working out failure messages for Sparky, and that’s how they are filed.) But char* x is different to char *x and the * is worrying me. Pointer. It’s a pointer of some sort. But is *char a pointer to a character… well, colour me ignorant. I’m guessing, not looking this up. It’ll end up explained.