[comp.lang.c] printf vs. vprintf

fillg1@uni-paderborn.de (Michael Illgner) (08/10/90)

Please excuse if this is an old topic in this group, but i am a
novice in ANSI C.

Can anyone describe the advantages (or disadvantages) in using
vprintf instead of printf?


|-----------------------------------------------------------------------------|
|It`s not dead,          | Michael Illgner          | email to                |
|It justs smells funny ! | Theodorstr. 27           |                         |
|                        | 4790 Paderborn (Germany) | fillg1@uni-paderborn.de |
|Life, Universe and all  | 05251/26488 or 60-2331   |                         |
------------------------------------------------------------------------------|
-- 

|-----------------------------------------------------------------------------|
|It`s not dead,          | Michael Illgner          | email to                |
|It justs smells funny ! | Theodorstr. 27           |                         |

browns@astro.pc.ab.com (Stan Brown, Oak Road Systems) (08/12/90)

In article <1990Aug10.120048.28576@uni-paderborn.de>, fillg1@uni-paderborn.de (Michael Illgner) writes:
> Can anyone describe the advantages (or disadvantages) in using
> vprintf instead of printf?

I've never used vprintf, and I've been Cing for 7 years now!  (Jean-Pierre,
grand-pere has passed 93 happy years in Choiseul-sur-Mer without once using the
past anterior verb form. --New Yorker cartoon :-) )

But seriously: If you have written a function that takes a variable number of
arguments, and inside the function you want to printf those arguments, or all of
them after the first so many, you would call vprintf to do it.  vprintf takes
exactly two arguments, a char* for the format, and a va_list containing the
other arguments.  That's the only usse I know for vprintf.

So at the risk of oversimplifying: always use printf.  vprintf is used only in
very special circumstances, which you're not likely to meet.

Stan Brown, Oak Road Systems, (216) 371-0043
The opinions expressed are mine. Mine alone!  Nobody else is responsible for
them or even endorses them--except my cat Dexter, and he signed the power of
attorney only under my threat to cut off his Cat Chow!

mercer@npdiss1.StPaul.NCR.COMDan Mercer) (08/16/90)

In article <411.26c40096@astro.pc.ab.com> browns@astro.pc.ab.com (Stan Brown, Oak Road Systems) writes:
:In article <1990Aug10.120048.28576@uni-paderborn.de>, fillg1@uni-paderborn.de (Michael Illgner) writes:
:> Can anyone describe the advantages (or disadvantages) in using
:> vprintf instead of printf?
:
:I've never used vprintf, and I've been Cing for 7 years now!  (Jean-Pierre,
:grand-pere has passed 93 happy years in Choiseul-sur-Mer without once using the
:past anterior verb form. --New Yorker cartoon :-) )
:
:But seriously: If you have written a function that takes a variable number of
:arguments, and inside the function you want to printf those arguments, or all of
:them after the first so many, you would call vprintf to do it.  vprintf takes
:exactly two arguments, a char* for the format, and a va_list containing the
:other arguments.  That's the only usse I know for vprintf.
:
:So at the risk of oversimplifying: always use printf.  vprintf is used only in
:very special circumstances, which you're not likely to meet.
:
:Stan Brown, Oak Road Systems, (216) 371-0043
:The opinions expressed are mine. Mine alone!  Nobody else is responsible for
:them or even endorses them--except my cat Dexter, and he signed the power of
:attorney only under my threat to cut off his Cat Chow!

He's absolutely correct.  I wrote a menuing system.  I wanted to make
it as easy to use as printf,  so I wrote a wprintf function (window
print).  I use vsprintf to print the string into a buffer,  then
parsed the buffer for %B (bold) %N (normal) %R (reverse) and
%D (dim) directives replacing them with the correct terminal sequences.
That's the only time I ever used the va_args capability.
-- 

Dan Mercer
Reply-To: mercer@npdiss1.StPaul.NCR.COM (Dan Mercer)
"MAN - the only one word oxymoron in the English Language"