Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #13646

Re: Variable argument function as a parameter of a variable argument function

Message-ID <4EC94804.4E9F@mindspring.com> (permalink)
Date 2011-11-20 13:33 -0500
From pete <pfiland@mindspring.com>
Organization PF
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>

Show all headers | View raw


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 <stdio.h>
#include <stdarg.h>

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

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Variable argument function as a parameter of a variable argument function AikidoGuy <aikidoguy@gmail.com> - 2011-11-19 23:02 -0800
  Re: Variable argument function as a parameter of a variable argument function Ark <akhasin@macroexpressions.com> - 2011-11-20 03:14 -0500
  Re: Variable argument function as a parameter of a variable argument function Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-20 08:07 -0500
    Re: Variable argument function as a parameter of a variable argument function Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-20 08:11 -0500
  Re: Variable argument function as a parameter of a variable argument function Keith Thompson <kst-u@mib.org> - 2011-11-20 08:19 -0800
  Re: Variable argument function as a parameter of a variable argument function pete <pfiland@mindspring.com> - 2011-11-20 13:33 -0500
    Re: Variable argument function as a parameter of a variable argument function AikidoGuy <aikidoguy@gmail.com> - 2011-11-20 15:29 -0800
      Re: Variable argument function as a parameter of a variable argument function Keith Thompson <kst-u@mib.org> - 2011-11-20 15:58 -0800
        Re: Variable argument function as a parameter of a variable argument function AikidoGuy <aikidoguy@gmail.com> - 2011-11-20 16:05 -0800
          Re: Variable argument function as a parameter of a variable argument function James Kuyper <jameskuyper@verizon.net> - 2011-11-20 20:45 -0500
            Re: Variable argument function as a parameter of a variable argument function AikidoGuy <aikidoguy@gmail.com> - 2011-11-20 20:18 -0800
              Re: Variable argument function as a parameter of a variable argument function James Kuyper <jameskuyper@verizon.net> - 2011-11-21 07:22 -0500
                Re: Variable argument function as a parameter of a variable argument function Seebs <usenet-nospam@seebs.net> - 2011-11-21 22:43 +0000

csiph-web