delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/13/10:29:51

From: "Andrew Jones" <luminous-is AT home DOT com>
Newsgroups: comp.os.msdos.djgpp
References: <001f864e DOT f7539fd2 AT usw-ex0103-018 DOT remarq DOT com>
Subject: Re: How do i make a printf type func?
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
Message-ID: <tkzp4.38011$45.2077485@news2.rdc1.on.home.com>
Date: Sun, 13 Feb 2000 14:37:13 GMT
NNTP-Posting-Host: 24.42.120.18
X-Complaints-To: abuse AT home DOT net
X-Trace: news2.rdc1.on.home.com 950452633 24.42.120.18 (Sun, 13 Feb 2000 06:37:13 PST)
NNTP-Posting-Date: Sun, 13 Feb 2000 06:37:13 PST
Organization: @Home Network Canada
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

> Heya,
> This is not a DJGPP question, but a C one. I hope you'll help
> anyway.
> Well, i want to make a function that will recieve a variable
> number of arguements. The first argument tells the function
> how much more arguments there are. I know how to declare it:
> int func(int n,...)
>
> but i don't know how to address the arguments.

Well, since everyone else referred you elsewhere, I'll try my hand.  This is a
modified version from K&R II.

#include <stdarg.h>
#include <stdio.h>

void Show(const char *format, ...)
  {
  char buffer[256]; /* this limits the maximum size of all arguments to 256
bytes */
  va_list args;
  va_start(args, format);
  vsprintf(buffer, format, args);
  va_end(args);
  fprintf(stderr, "you said: %s", buffer);
  }

Will display to stdout whatever you send it.  The vsprintf function
automagically handles all the normal printf format identifiers (like %s, %c
etc...).

But you should read up on each individual part of this too.  Check your
documentation.

AndrewJ


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019