Message-Id: <199807210930.GAA07054@swan2.uspnet.usp.br> Comments: Authenticated sender is From: "Hilton Fernandes" To: djgpp mailing list , "Sean Middledich" Date: Tue, 21 Jul 1998 06:29:40 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: djgpp daily digest for 20 Jul 1998 2/2 Reply-to: Hilton Fernandes CC: "Hilton Fernandes" In-reply-to: <199807210406.AAA22718@delorie.com> Precedence: bulk On 19 Jul 1998 15:02:36, "Sean Middledich" wrote: > I was wondering how to the ... to make a printf type function. My current > project uses a screen buffer, but the function I use to write strings to the > buffer can only use one string at a time. If I wanted to do a porintf type > effect, I have to do this: > > char Text[81]; > > sprintf ( Text, "String A: %s, Number A: %d", StringA, NumB ); > Print ( Text ); > > I would love to take out the business with Text[81] and sprintf. I just > need to know how to use the ... ( elipse was it called? ). > > Sean Middleditch ( the baffled programmer ) > of > AwesomePlay Productions > http://www.angelfire.com/biz/aweplay > aweplay AT hotmail DOT com > Hi! Please take a look at this very simple fprintff (fprintf with a flush): #include /* va_list, va_start(), va_end */ int fprintff ( FILE* out_f, const char* format, ... ) { int ret_val; va_list arg; va_start(arg, format); ret_val = vfprintf(out_f, format, arg); va_end(arg); if (fflush (out_f) == EOF) { return (EOF); } return (ret_val); } /* int fprintff (FILE*, char*, ...) */ All you gotta do to make it become what you want is to change vfprintf() to vsprintf(). And remove fflush(), of course. In the example above, vfprintf() does the real magic, following the argument list; va_start() is a macro that just makes arg point to the next argument after format. If there's one, of course. Last __but__ least, va_arg() is the do-nothing macro and generates the empty text. Regards, --Hilton