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

B

Bore Biko

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 !!
(e-mail address removed)-com.hr
 
U

Ulrich Eckhardt

Bore said:
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
 
P

Park Sung-jae

Bore said:
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 !!
(e-mail address removed)-com.hr
use va_arg, va_list, etc..
 
B

Bore Biko

Park Sung-jae said:
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..!!
 
K

Keith Thompson

Bore Biko said:
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.
 
M

Malcolm

Keith Thompson said:
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.
 
D

David Shin

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top