Date: Wed, 1 Jul 2009 21:39:43 -0300 From: "Carlos A. M. dos Santos" <unixmania@gmail.com> To: Alfred Perlstein <alfred@freebsd.org> Cc: rick-freebsd2008@kiwi-computer.com, freebsd-hackers@freebsd.org, Alexander Best <alexbestms@math.uni-muenster.de> Subject: Re: c question: *printf'ing arrays Message-ID: <e71790db0907011739q59023141ve4209bcd83c04683@mail.gmail.com> In-Reply-To: <20090630225457.GR84786@elvis.mu.org> References: <20090630210238.GA33849@keira.kiwi-computer.com> <permail-2009063022060580e26a0b00003f4a-a_best01@message-id.uni-muenster.de> <20090630225457.GR84786@elvis.mu.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jun 30, 2009 at 7:54 PM, Alfred Perlstein<alfred@freebsd.org> wrote= : > Hey Alex, > > People frown on macros, but this could be a good one: > > #define SPRINT(f, fmt) \ > =A0 =A0 =A0 =A0do {\ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for (_i =3D 0; _i < sizeof(f)/sizeof(f[0])= ; i++) \ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printf(fmt, f[i]); \ > =A0 =A0 =A0 =A0}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. --=20 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e71790db0907011739q59023141ve4209bcd83c04683>