Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 20 Nov 2011 12:33:56 -0600 Message-ID: <4EC94804.4E9F@mindspring.com> Date: Sun, 20 Nov 2011 13:33:40 -0500 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Variable argument function as a parameter of a variable argument function References: <00f0752d-f768-437a-87c5-0b3767c7411f@l24g2000yqm.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 61 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.218.83 X-Trace: sv3-9SRWJhcbZPBSa/rICG6VAWOmawWy4Tz2UXsREBHOovML8QJhHaG0+tAHTFuXjaqUIjMhwqhp50hufkP!r6Ic2oRsDsquQ9kfkSpTKzVrT6so+Lxv81Z6I6BkET2xgGO8tMGOHFde5hEyVQl9/ESgU38j4sdj!kiwwm/xjoQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2378 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:13646 AikidoGuy wrote: > > Hi everyone, > > I've done a little searching, but I can't quite find an answer to my > question. Everything I've found is more related to how to construct a > variable argument function, and that's not my question. > > Suppose I have a variable argument function. Is it possible to use it > to initialize a parameter of another variable argument function? > > For example, printf("%s", varArgFcnReturningAString(a,b,c)); > > I ask because I'm not sure if this is supported by the standard and/or > could be compiler specific. > > Thank you for any help, tips, and suggestions! /* BEGIN output from new.c */ Yes, it is possible. /* END output from new.c */ /* BEGIN new.c */ #include #include char *varArgFcnReturningAString(char *s, const char *format, ...) { va_list arg; va_start(arg, format); vsprintf(s, format, arg); va_end(arg); return s; } int main(void) { char *b = "%s"; char c[] = "Yes, it is possible."; char a[sizeof c] = {0}; puts("\n/* BEGIN output from new.c */\n"); printf("%s", varArgFcnReturningAString(a, b, c)); puts("\n\n/* END output from new.c */"); return 0; } -- pete