Basically, the string is a run-length encoding of the image: Alternating characters in the string say how many times to draw a space, and how many times to draw an exclamation mark consecutively. Here is an analysis of the different elements of this program:
The encoded string
The first 31 characters of this string are ignored. The rest contain instructions for drawing the image. The individual characters determine how many spaces or exclamation marks to draw consecutively.
Outer for loop
This loop goes over the characters in the string. Each iteration increases the value of b
by one, and assigns the next character in the string to a
.
Inner for loop
This loop draws individual characters, and a newline whenever it reaches the end of line. The number of characters drawn is a - 64
. The value of c
goes from 10 to 90, and resets to 10 when the end of line is reached.
The putchar
This can be rewritten as:
++c;
if (c==90) { //'Z' == 90
c = 10; //Note: 10 == '\n'
putchar('\n');
}
else {
if (b % 2 == 0)
putchar('!');
else
putchar(' ');
}
It draws the appropriate character, depending on whether b
is even or odd, or a newline when needed.