Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

vsnprintf like

Thread view: 
stef - 20 Aug 2007 16:07 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, ...)
{
 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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.