Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to write function with multiple parameters...??

Reply
Thread Tools

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

 
 
Bore Biko
Guest
Posts: n/a
 
      10-30-2005
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 !!



 
Reply With Quote
 
 
 
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      10-30-2005
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


 
Reply With Quote
 
 
 
 
Park Sung-jae
Guest
Posts: n/a
 
      10-30-2005
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 !!
>
>
>

use va_arg, va_list, etc..
 
Reply With Quote
 
Bore Biko
Guest
Posts: n/a
 
      10-30-2005

Park Sung-jae <> wrote in message
news:dk2vlb$ot3$...
> 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 !!
> >
> >
> >

> 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..!!


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-30-2005
"Bore Biko" <> writes:
> Park Sung-jae <> wrote in message
> news:dk2vlb$ot3$...
>> 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 !!
>> >
>> >
>> >

>> 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) kst- <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.
 
Reply With Quote
 
Malcolm
Guest
Posts: n/a
 
      10-30-2005

"Keith Thompson" <kst-> 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.


 
Reply With Quote
 
David Shin
Guest
Posts: n/a
 
      10-31-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to use Response.write to write to a specific area on a aspx pa =?Utf-8?B?QWJlbCBDaGFu?= ASP .Net 6 05-03-2006 10:16 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
DVD Write speed - Not able to write at 8 speed Vincent Wonnacott Computer Support 1 09-16-2004 03:14 PM
Using write function within email Module to write get_payload to afile. Chuck Amadi Python 0 06-22-2004 12:13 PM



Advertisments