Hello,
I would like to do my "own" printf.
Under C I used to play with the classic "vsnprintf" :
void print_it(char *app, size_t num, ...)
{
va_list arg;
char buf[1024];
...
va_start(arg, num);
vsnprintf(buf, ..., ..., arg);
...
}
How could I do that with Java ?
thanks for your help...
Joshua Cranmer - 20 Aug 2007 17:58 GMT
> Hello,
>
> I would like to do my "own" printf.
> Under C I used to play with the classic "vsnprintf" :
>
> void print_it(char *app, size_t num, ...)
Using Java 5, the method header would look like:
void print_it(String app, Object ... args)
The args object would act like an array of Objects.

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
Mark Rafn - 20 Aug 2007 20:24 GMT
>I would like to do my "own" printf.
Why your "own", rather than a built-in one?
>Under C I used to play with the classic "vsnprintf" :
Under 1.5 and later PrintStream has a format(String, Object...) method. This
is pretty close to the C printf methods. Or just use the java.util.Formatter
directly.
--
Mark Rafn dagon@dagon.net <http://www.dagon.net/>

Signature
Posted via a free Usenet account from http://www.teranews.com