Learn C the Hard Way – chars and strings and tigers and bears

‘Kay. So now we’re looking at the char[] without a *. So I’m going to guess that the * means multiple argvs of type char[] are available. Still keeping that on the back burner.

I’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’s %05d – but I don’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’m happier trying that, although I believe I need sprintf – stringprint. Again, not a thing to look at yet.

Breaking things for extra credit:

char x = ”; is an error. Char is explicitly 1 character long. Related to the ” instead of “” I figger.

char x[] = “” isn’t an error. It’s 0 length but that doesn’t really matter. It’s initialised as a space for there to be a string, and that’s that.

printf("")

– sort of funny. How can you tell if it’s done anything? I’m assuming it exists because the compiled program has some size, and I left it on its own in there, but it’s a 0-length string. The compiler doesn’t like it, but goes for it anyhow, but when you run it nothing appears to happen.

By law I must now link to Oglaf’s Fountain of Doubt. (SFW)

Subtle, isn’t it?

Putting an int into a char results in the character returned being (I guess) ASCII result for that integer value. So that’s not broken, but it’s potentially unexpected. That’s how I got H out for integer 72 in an earlier exercise.

According to www.cdf.toronto.edu/~ajr/209/notes/printf.html s is already a char pointer. I think that’s just a sign that says ‘use this long thing over here’ instead of having to write out what the long thing is in a compressed space.