25 Jan 2002 landonf   » (Journeyer)

brain teasers
I spent some time today doing some C brain teasers.
Anyone know a good location for some challenging ones?

Do not reuse code from this solution, you'll regret it.
void main(int argc, char **argv)
{

    char *string = (argv[1] ? strdup(argv[1]) : strdup("This is a very long test string")), *p = string, *e = string, *s;
    while(*p != '\0')
    {
      while(*p != ' ' && *p != '\0')
        p++;
      s = p--;
      while(p > e)
        *e ^= *p ^= *e++ ^= *p--;
        p = s;
        e = ++p;
    }
    printf("%s\n", string);
}

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!