By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

How to write function with multiple parameters...??

P: n/a
I don't know hopw to do this,
like "printf", or "sprintf", I know
they use a stack but how to make
my own...??

Thanks in advance !!
ro***********@si.t-com.hr
Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Bore Biko wrote:
I don't know hopw to do this,
like "printf", or "sprintf", I know
they use a stack but how to make
my own...??


So you don't mean 'multiple parameters' but 'a variable number of
parameters', I guess. These functions are called 'variadic' and
implemented with va_list and associated macros. Use google to find out
more and don't hesitate to ask here if you encounter problems.

Uli
Nov 15 '05 #2

P: n/a
Bore Biko wrote:
I don't know hopw to do this,
like "printf", or "sprintf", I know
they use a stack but how to make
my own...??

Thanks in advance !!
ro***********@si.t-com.hr

use va_arg, va_list, etc..
Nov 15 '05 #3

P: n/a

Park Sung-jae <da*****@kornet.net> wrote in message
news:dk**********@news2.kornet.net...
Bore Biko wrote:
I don't know hopw to do this,
like "printf", or "sprintf", I know
they use a stack but how to make
my own...??

Thanks in advance !!
ro***********@si.t-com.hr

use va_arg, va_list, etc..


Thanks,
I undrstand now, the all is
in fact htat first(or argument
in which we give format) is
a linked list...

Thanks, Robert..!!
Nov 15 '05 #4

P: n/a
"Bore Biko" <bo*******@yahoo.co.uk> writes:
Park Sung-jae <da*****@kornet.net> wrote in message
news:dk**********@news2.kornet.net...
Bore Biko wrote:
> I don't know hopw to do this,
> like "printf", or "sprintf", I know
> they use a stack but how to make
> my own...??
>
> Thanks in advance !!
> ro***********@si.t-com.hr
>
>

use va_arg, va_list, etc..


Thanks,
I undrstand now, the all is
in fact htat first(or argument
in which we give format) is
a linked list...


No, the format string in a printf() call is not a linked list.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5

P: n/a

"Keith Thompson" <ks***@mib.org> wrote
Thanks,
I undrstand now, the all is
in fact htat first(or argument
in which we give format) is
a linked list...


No, the format string in a printf() call is not a linked list.

I don't think Bore's first language is English.

When you pass a variable number of arguments to a function, it needs to have
some way of knowing how many arguments were passed.

In the printf() family of functions this is achieved by passing a format
string as the first parameter. Each type (introduced by a % sign) matches an
arguement.

However you cna write your own varidic functions. You could pass in an
integer as the first arguement giving the number of arguments, or you could
even pass in an elaborate structure (like a tree or a linked list) which
the function parses to find the number of arguments.
Nov 15 '05 #6

P: n/a
Set your function prototype as:

int abc(int num, ...);

then use stdarg.h to parse the arguments.

This will allow user to pass in multiple parameters:

abc(5, 4);
abc(5, 4, 3);
abc(5, 4, 3, 2, 1);

Hope this helps.

Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.