I have stopped reading Stephen King novels. Now I just read C code instead. - Richard O'Keefe

the brown-dragon blog

C! Oh C!

2008-12-17

When I joined this C/C++ shop after nearly six years of Java, I spent a bit of time brushing up on my then rusty C/C++ skills.

During that time I wrote this fun little program simply because it was something I could never have done in Java. At the time I had not heard of The International Obfuscated C Code Contest, which also looks like great fun. :-)

This is the compiled version: oh-c.exe

And here is the code: :-)

oh-c.c

#include <stdio.h>

int
main (void)
{
    char* _ = "/B/ /;9/ 999/4/ 999/ /:9///F/ 9*9/5/ 9*9/4/ 9*9/ 9*9///F/ *9*/5/ *9*/4/ *9*/ *9*///F/ *\"*/5/ *\"**9**\"**/ *\"**9**\"///F/ *\"*/5/ *\"*/4/ *\"*/ *\"*///F/ \"*\"/5/ \"*\"/4/ \"*\"/ \"*\"///F/ \"\"\"/5/ \"\"\"/4/ \"\"\"/ /:\"/////7/ /99/ / /99/ / / /89/ / 999/7/ 999/ /49/4/ 999///7/ 9*9/4/ 9*9/ 9*9/4/ 9*9/ 9*9/4/ 9*9/ 9*9/7/ 9*9/ 9*9*9/ / / 9*9///7/ *9*/4/ *9*/ *9*/4/ *9*/ *9*/4/ *9*/ *9*/7/ *9*/ 9*9*9*/ / *9*///7/ *\"**9**\"*/ / *\"**9**\"9/ / *\"*/4/ *9*/ *\"*/ / *9*/ / *\"*/ *\"*/ *9*/ *\"*///7/ *\"*/4/ *\"*/ *\"*/4/ *\"*/ *\"*/4/ *\"*/ *\"*/ *\"*\"*/ *\"*/ *\"*/ / *\"*\"*\"///7/ \"*\"/4/ \"*\"/ \"*\"/4/ \"*\"/ \"*\"/4/ \"*\"/ / \"*\"*\"/ \"*\"*\"/ / \"*\"/ / / \"*\"*\"///7/ /9\"/ / \"\"\"/4/ \"\"\"/ / /8\"/4/ \"\"\"/ / / \"\"\"/ / / \"\"\"/4/ /4\"/////4/ /99/ / /99/6/ 999/6/ /89/ / / /89/ / /49/4/ 999///4/ 9*9/4/ 9*9/ 9*9/4/ 9*9/ / / 9*9/ 9*9/ / / 9*9/4/ 9*9/ 9*9/4/ 9*9/ 9*9*9/ / / 9*9///4/ *9*/4/ *9*/ *9*/4/ *9*/ / *9*/ / / *9*/ / *9*/8/ *9*/4/ *9*/ 9*9*9*/ / *9*///4/ *\"*/4/ *9*/ *\"**9**\"9/ / *\"**9**\"**9/ 9\"9/8/ *\"*/4/ *9*/ *\"*/ *9*/ *\"*///4/ *\"*/4/ *\"*/ *\"*/4/ *\"*/ *\"*/5/ *\"*/ *\"*/ / / *\"*\"/ *\"*/4/ *\"*/ *\"*/ / *\"*\"*\"///4/ \"*\"/4/ \"*\"/ \"*\"/4/ \"*\"/ \"*\"/5/ \"*\"/ \"*\"/4/ \"*\"/ \"*\"/4/ \"*\"/ \"*\"/ / / \"*\"*\"///4/ /9\"/ / \"\"\"/4/ \"\"\"/ \"\"\"/5/ \"\"\"/ / /8\"/ / / /8\"/ / \"\"\"/4/ /4\"";
    int o;

    /* Look Ma! No braces! */
    while (*_)
        if ('/' == *_)
            if ((' ' == *++_) || ('[' == *_))
                printf ("%c", *_++);
            else if ('/' == *_)
                printf ("\n"),++_;
            else
                for (o = ('/'==*(_+1))?++_,(*(_++-1)-'0')|0x100:*_++-'0';
                        (o--&~0x100);(o&~0x100)?_:++_)
                    printf ("%c", (o&0x100)?('/'==*_)?'\n':*_:*_+1);
        else
            printf ("%c", *_+++1);


    getc (stdin); /* Wait for use input */
    return 0; /* All done! */
}

Try and work out what it does before running it. My wife managed to get it basically right, so it should be possible.

Other Posts

(ordered by Tags then Date)