CompuServe Thread

Variable Arguments

3 messages in this thread
#1191From: LANCE SHORBSep 27, 1990 10:48 PM
I'm interested in passing variable arguments, and then passing them again onto a routine that accepts variable argument. I would appreciate suggestions regarding a method to this idea. Below is an attempt, which Aztec 5.0b stops on the line marked below. Again, solutions or ideas would be appreciated. /********** Test of passing of varying arguments **********/ #include <stdarg.h> #include <stdio.h> void main() { int a,b,c,d; a=1;b=2;c=3;d=4; testf("Here goes: a=%d b=%d c=%d d=%d \n\n",a,b,c,d); } void testf(str,…)/*** Compiler says 'invalid function arg'***/ va_list arg; char *str { va_list arg; printf(str,arg); return(); }
#1216From: Mike Spille/ManxSep 28, 1990 5:54 PM
Try this: void testf (str, …) char *str; /* I prefer to use ANSI syntax BTW, even though its ugly */ { va_list arg; va_start (arg, str); vprintf (str, arg); va_end (arg); } The main point is use of vprintf instead of printf. There's a big difference between a function which takes a variable number of arguments, like printf: int printf (const char *format, …); and a function which takes a variable argument list, like vprintf: int vprintf (const char *format, va_list arg); Let me know if you have anymore questions. -Mike
#1236From: LANCE SHORBSep 29, 1990 10:47 AM
Thanks for the info Mike, Vsprintf etc. had slipt pass my eyes. It works fine. Thanks, Lance – via Whap!