home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: Multiple Parameter Passing (unspecified number)
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1992Nov17.093123@rbg.informatik.th-darmstadt.de>
- Date: Tue, 17 Nov 1992 08:31:23 GMT
- References: <92321.124834GNR100@psuvm.psu.edu>
- Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
- Organization: TU Darmstadt
- Lines: 32
-
- In article <92321.124834GNR100@psuvm.psu.edu>, <GNR100@psuvm.psu.edu> writes:
- > Hi.
- >
- > I'm looking to write a function that accepts any number of paramerter.
- > There will be at least two, an int and a char[]. The rest will all be char[]'s.
- > I need to know how this is done. The meathod would be similar to that of
- > printf(), so if anybody know how that works, please let me know.
-
- If you use an ANSI compiler it will look like this:
-
- #include <stdarg.h>
-
- void fun(int i,char s[],...) /* 3 dots exactly */
- { va_list argp;
- /* more variables */
-
- va_start(argp,s); /* 2nd arg is last named fun-arg */
- /* with va_arg(argp, TYPENAME) you can step through the arg-list,
- the macro will provide always the next one, TYPENAME is the type
- of the arg (in this case char * or char [])
- */
- /* some code */
- va_end(argp);
-
- }
-
- Hope this will help,
- Walter
-
- --
- Walter Misar
- misar@rbhp56.rbg.informatik.th-darmstadt.de
-