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

Discussion in 'C Programming' started by Bore Biko, Oct 30, 2005.

  1. Bore Biko

    Bore Biko Guest

    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 !!
    -com.hr
    Bore Biko, Oct 30, 2005
    #1
    1. Advertising

  2. 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
    Ulrich Eckhardt, Oct 30, 2005
    #2
    1. Advertising

  3. 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 !!
    > -com.hr
    >
    >

    use va_arg, va_list, etc..
    Park Sung-jae, Oct 30, 2005
    #3
  4. Bore Biko

    Bore Biko Guest

    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 !!
    > > -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..!!
    Bore Biko, Oct 30, 2005
    #4
  5. "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 !!
    >> > -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) <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.
    Keith Thompson, Oct 30, 2005
    #5
  6. Bore Biko

    Malcolm Guest

    "Keith Thompson" <> 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.
    Malcolm, Oct 30, 2005
    #6
  7. Bore Biko

    David Shin Guest

    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.
    David Shin, Oct 31, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. komal
    Replies:
    6
    Views:
    1,421
    msalters
    Jan 25, 2005
  2. Chuck Amadi
    Replies:
    0
    Views:
    518
    Chuck Amadi
    Jun 22, 2004
  3. Jason
    Replies:
    2
    Views:
    506
    Jonathan Mcdougall
    May 13, 2006
  4. jodleren

    multiple parameters in function

    jodleren, Jul 2, 2008, in forum: Javascript
    Replies:
    1
    Views:
    101
    Henry
    Jul 2, 2008
  5. Victor Bazarov
    Replies:
    7
    Views:
    485
    Zhihao Yuan
    Nov 30, 2012
Loading...

Share This Page