Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!tut.cis.ohio-state.edu!att!dptg!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Variable number of arguments to a function Keywords: c, variable number of arguments, sprintf Message-ID: <10791@alice.UUCP> Date: 6 May 90 14:05:13 GMT References: <3697@iitmax.IIT.EDU> Distribution: na Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 49 In article <3697@iitmax.IIT.EDU>, thssvhj@iitmax.IIT.EDU (vijay hemraj jadhwani) writes: > myprint(stream, fmt, a1, a2, a3, a4, a5) /* Function definition */ > FILE *stream; > char *fmt; > { > ... some initialization and assignment ... > sprintf(stream, fmt, a1, a2, a3, a4, a5); > . > . > . > } > 1. Which of the above 3 cases are correct and which are not? Why ? None of them. The myprint() function itself is non-portable and in fact will not work on many implementations. > 2. If I want to remove any "lint" warnings, for argument number mismatch, > what should I do ? i.e. I need a scheme to be able to pass variable > number of arguments to myprint(). Also it would be nice , if I could > also have an ability to pass any "type" of arguments to myprint(). If you want something that works, and not just something that shuts lint up, you must use either or for an ANSI C implementation. You must also use vfprintf, which interfaces explicitly with or . Example: #include myprint(va_alist) va_dcl { va_list ap; FILE *stream; char *fmt; va_start(ap); stream = va_arg(ap, FILE *); fmt = va_arg(ap, FILE *); /* ... some initialization and assignment ... */ vsprintf(stream, fmt, ap); /* and so on */ } -- --Andrew Koenig ark@europa.att.com