c question: *printf'ing arrays

Carlos A. M. dos Santos unixmania at gmail.com
Thu Jul 2 00:39:46 UTC 2009


On Tue, Jun 30, 2009 at 7:54 PM, Alfred Perlstein<alfred at freebsd.org> wrote:
> Hey Alex,
>
> People frown on macros, but this could be a good one:
>
> #define SPRINT(f, fmt) \
>        do {\
>                for (_i = 0; _i < sizeof(f)/sizeof(f[0]); i++) \
>                        printf(fmt, f[i]); \
>        }while(0)
>
> :D
>
> This should allow you to point to any _array_ and print each
> element of it using format "fmt".
>
> Example:
> SPRINT(Header->game_title, "%c");

Yes, it works, but using a loop to print a character array one char at
a time is terribly inefficient.

-- 
My preferred quotation of Robert Louis Stevenson is "You cannot
make an omelette without breaking eggs". Not because I like the
omelettes, but because I like the sound of eggs being broken.


More information about the freebsd-hackers mailing list