• Create Account

We're offering banner ads on our site from just \$5!

### #Actualboogyman19946

Posted 28 January 2014 - 08:23 PM

#include <stdio.h>

int main (void)
{
#define P(A)printf(A,i,i,i)
#define B(A,P)#A" bottle"#P" of beer on the wall"
#define V(P)B(%d,P)", %d bottle"#P" of beer.\nTake one down and pass it around, "

int i=99;
P(V(s));

#define R B(%d,s)".\n\n"V(s)

while(--i>1)
P(R);

#define R B(1,\?\b)".\n\n"V(\?\b)

P(R B(no more,s)".\n\n"B(No more,s)", no more bottles of beer.\nGo to the store and buy some more, "B(99,s)".\n");
}


378 characters including significant whitespace, 396 with the #include . Output is perfect including caps, punctuation, newlines and final verses. I could probably hoist out a few #defines, or #define the #defines and save another 20-30 chars, but I'm weary of this exercise for the moment Gotta love code that only reads top to bottom!

Codepad seems to be messing up your output. At the 1 bottle of beer line, it prints bottle? instead of bottle, although my console seems to get it right.

### #1boogyman19946

Posted 28 January 2014 - 08:19 PM

#include <stdio.h>

int main (void)
{
#define P(A)printf(A,i,i,i)
#define B(A,P)#A" bottle"#P" of beer on the wall"
#define V(P)B(%d,P)", %d bottle"#P" of beer.\nTake one down and pass it around, "

int i=99;
P(V(s));

#define R B(%d,s)".\n\n"V(s)

while(--i>1)
P(R);

#define R B(1,\?\b)".\n\n"V(\?\b)

P(R B(no more,s)".\n\n"B(No more,s)", no more bottles of beer.\nGo to the store and buy some more, "B(99,s)".\n");
}


378 characters including significant whitespace, 396 with the #include . Output is perfect including caps, punctuation, newlines and final verses. I could probably hoist out a few #defines, or #define the #defines and save another 20-30 chars, but I'm weary of this exercise for the moment Gotta love code that only reads top to bottom!

Codepad seems to be messing up your output. At the 1 bottle of beer line, it prints bottle? instead of bottle.

PARTNERS