On Sat, 20 Sep 2008 12:53:31 -0700, Thomas Hruska
<[EMAIL PROTECTED]> wrote Re Re: [c-prog] printf min fild width:
>Vic Dura wrote:
>> Hello,
>>
>> Is there anyway to specify the printf minimum field width at runtime?
>> For example in
>>
>> printf("%5d", i);
>>
>> the min filed width is 5. I would like to calculate the min width at
>> run-time, e.g. printf(%Wd", i); where W is calculated prior to the
>> printf.
>>
>> Thanks for any suggestions.
>
>printf("%*d", 5, i);
>
>Something like that?
YES!!
That works perfectly! Thanks for the tip.
As an added bonus, now knowing what to look for, I was able to read
about how to use the * with %f, e.g
printf("%*.*f", w,p, floatNum);
to determine width and precision at run-time.
That's very neat :-)
Thanks again.
C.R.
--
At first they laugh at you, then they ignore you, then they fight you, then you
win.