home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16651 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.5 KB  |  45 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sdd.hp.com!caen!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  3. From: misar@rbg.informatik.th-darmstadt.de (walter misar)
  4. Subject: Re: Multiple Parameter Passing (unspecified number)
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1992Nov17.093123@rbg.informatik.th-darmstadt.de>
  7. Date: Tue, 17 Nov 1992 08:31:23 GMT
  8. References:  <92321.124834GNR100@psuvm.psu.edu>
  9. Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
  10. Organization: TU Darmstadt
  11. Lines: 32
  12.  
  13. In article <92321.124834GNR100@psuvm.psu.edu>, <GNR100@psuvm.psu.edu> writes:
  14. >    Hi.
  15. >    I'm looking to write a function that accepts any number of paramerter.
  16. > There will be at least two, an int and a char[]. The rest will all be char[]'s.
  17. > I need to know how this is done.  The meathod would be similar to that of
  18. > printf(), so if anybody know how that works, please let me know.
  19.  
  20. If you use an ANSI compiler it will look like this:
  21.  
  22. #include <stdarg.h>
  23.  
  24. void fun(int i,char s[],...)    /* 3 dots exactly    */
  25. {  va_list argp;
  26.     /* more variables */
  27.  
  28.    va_start(argp,s);        /* 2nd arg is last named fun-arg    */
  29.     /* with va_arg(argp, TYPENAME) you can step through the arg-list,
  30.        the macro will provide always the next one, TYPENAME is the type
  31.        of the arg (in this case char * or char [])
  32.     */
  33.     /* some code */
  34.     va_end(argp);
  35.  
  36. }
  37.  
  38. Hope this will help,
  39. Walter
  40.  
  41. -- 
  42. Walter Misar
  43. misar@rbhp56.rbg.informatik.th-darmstadt.de
  44.