Path: utzoo!mnetor!uunet!husc6!psuvax1!gondor.cs.psu.edu!schwartz From: schwartz@gondor.cs.psu.edu (Scott E. Schwartz) Newsgroups: comp.lang.c Subject: Re: variable number of arguments Message-ID: <3307@psuvax1.psu.edu> Date: 20 Feb 88 00:23:10 GMT References: <1608@byzantium.UUCP> Sender: netnews@psuvax1.psu.edu Reply-To: schwartz@gondor.cs.psu.edu (Scott E. Schwartz) Organization: Penn State University Lines: 24 Keywords: arguments In article <1608@byzantium.UUCP> richwill@byzantium.UUCP (Rich Williamson) writes: >I'm trying to put together a simple formatted output routine for >X-Windows. I would like to be able to say something like this > MyXText( X, Y, formatString, arg1, ... , argn ); >I would like to pass the necessary parameters to sprintf but I >don't know how to declare the arguments to MyXText. I don't know >how to declare a variable number of arguments. Is it even possible? >The family of printf() functions seem to be able to receive variable >arguments, so it would seem to possible. Hi Rich, how's life back at Swat? Anyway, you should look at the man page for varargs. Varargs is the only portable way to pass a varying number of arguments to a procedure. Since you want to use sprintf inside of MyXText, and since you are using a Sun with System V compatible libraries, you should strongly consider using vsprintf(), which directly takes the (varargs definded) parameters to MyXText, saving you from having to unpack arg1...argn and pass them to sprintf(). -- Scott Schwartz schwartz@gondor.cs.psu.edu