472,961 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,961 software developers and data experts.

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

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
6 3774
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
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

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
"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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
21
by: Gerry Abbott | last post by:
Hi All, If completed a script which parses a string into fragments (fields), then assigns these substrings into an array. I wish to turn this into a function to which i can pass the string....
21
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
2
by: Harshankumar | last post by:
Hello, I have the following questions 1) can we pass the parameters to interrupt? 2)can we return the parameters from interrupt Regards harshan
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
5
by: Sumana | last post by:
Hi All, We developed our project on VC++.Net console application to create image of disk and to write the image We are having problem with reading and writing the sector beyond 6GB Disk or...
3
by: ryan.mitchley | last post by:
Hi all I have a class (cPort) that is designed to receive objects and, depending on the type, call a handler (callback) in any descendant of a cProcessBlock class. Callback functions take a...
4
by: Nathan Sokalski | last post by:
I am a beginner with AJAX, and have managed to learn how to use it when passing single parameters, but I want to return more than one value to the client-side JavaScript function that displays it....
10
by: rh0dium | last post by:
Hi all, Below is a basic threading program. The basic I idea is that I have a function which needs to be run using a queue of data. Early on I specified my function needed to only accept basic...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.