Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Aristotle (5147)


Blah blah blah blah blah []

Journal of Aristotle (5147)

Thursday April 21, 2005
09:56 PM

Sometimes I like C a lot

[ #24310 ]

#include <stdio.h>

main( int argc, char *argv[] )
    // imagine this coming from STDIN instead
    char *stringlist = "foo\0bar\0baz\0quux\0"; // double-NUL terminated!!
    while( *stringlist ) {
        printf( "%s\n", stringlist ); // imagine open() here instead
        while( *( stringlist++ ) );
        // look ma, no copying!
    return 0;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Wow, my C is really rusty. Took me a moment to realize why the last while wasn't a bug :)

    • Yes, it’s very dense code. It took me a moment to get right! :)

      If it wasn’t for the ineffably laborious tedium of memory micromanagement that is all too frequently necessary, I’d spend a lot more time writing C. (I see that as a failing of the standard library much more so than of the language itself.)

  • And one of them is the beutifully concise code one can write for such string manipulation tasks. I just *love* seeing them pointers fly :-)